请问:java代码如何判断服务是否启动?谢谢!!

急求: java代码如何判断服务是否启动?谢谢!!

3个回答

一般服务启动都是启动在某IP的某个端口上,通过Socket去连下你们服务启动的IP和端口。看是否能连的通。如果连的通,表示服务已启动,但请注意,服务启动不代表服务一定正常可用。

附上代码。

    /**
     * 
     * 测试连接服务器
     *
     * @param ip 服务器IP
     * @param port 服务器端口
     * @return 连接成功返回<code>true</code>,连接失败返回<code>false</code>.
     */
    public boolean testServerConnect(String ip,int port) {
        boolean result = false;
        Socket connect = new Socket();
        try {
            connect.connect(
                new InetSocketAddress(ip, port), 1000); //连接服务器,每隔1秒重试
            result = connect.isConnected();
            return result;
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                connect.close();
            } catch (IOException e) {
                 e.printStackTrace();
            }
        }
        return result;
    }

不知道你说的服务是指什么服务呢

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
请问:用java代码调用memcached的启动,为何memcached没有反应?谢谢!
![图片说明](https://img-ask.csdn.net/upload/201507/15/1436967308_332255.png)
菜鸟学SpringMVC 写第一个代码就卡主了,启动tomcat就报错,求大神们帮帮忙呀,谢谢咯~
# 这个是controller类代码 ![图片说明](https://img-ask.csdn.net/upload/201705/07/1494086895_452573.png) # 这个是Applicationcontext.xml的配置 ![图片说明](https://img-ask.csdn.net/upload/201705/07/1494086936_702748.png) # 这个是web.xml的配置 ![图片说明](https://img-ask.csdn.net/upload/201705/07/1494086676_725308.png) # 这个 是jsp ![图片说明](https://img-ask.csdn.net/upload/201705/07/1494086713_854071.png) #这个是配置文件的位置图 ![图片说明](https://img-ask.csdn.net/upload/201705/07/1494086754_169926.png) #下面是报错内容: 严重: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [controller.HelloController] for bean with name 'hc' defined in class path resource [applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: controller.HelloController Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [controller.HelloController] for bean with name 'hc' defined in class path resource [applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: controller.HelloController at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651) at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:602) at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665) at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:521) at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:462) at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) at javax.servlet.GenericServlet.init(GenericServlet.java:158) at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1197) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5327) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5617) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [controller.HelloController] for bean with name 'hc' defined in class path resource [applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: controller.HelloController at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1281) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:575) at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1350) at org.springframework.beans.factory.support.AbstractBeanFactory.isSingleton(AbstractBeanFactory.java:411) at org.springframework.context.support.AbstractApplicationContext.isSingleton(AbstractApplicationContext.java:1137) at org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(AbstractUrlHandlerMapping.java:286) at org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.registerHandlers(SimpleUrlHandlerMapping.java:129) at org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.initApplicationContext(SimpleUrlHandlerMapping.java:104) at org.springframework.context.support.ApplicationObjectSupport.initApplicationContext(ApplicationObjectSupport.java:119) at org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext(WebApplicationObjectSupport.java:72) at org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:73) at org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:117) at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:92) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapabl Caused by: java.lang.ClassNotFoundException: controller.HelloController 五月 06, 2017 11:42:11 下午 org.apache.catalina.core.StandardContext loadOnStartup 严重: Servlet [springmvc] in web application [/com.yzl.springTest] threw load() exception java.lang.ClassNotFoundException: controller.HelloController # 代码跟教材一模一样,不知道是不是配置文件的位置放错地方了..很郁闷啊.... # 求大神们想想办法,没有金币咯~拜托拜托.
我想用java建立tcp/ip服务器然后用flash接受服务器发送的数据,同事将数据发送给js代码然后进一步操作
服务器代码: package JSocket; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class Server { private static final int PORT = 3000; // 端口号 private static List<Socket> list = new ArrayList<Socket>(); // 保存连接对象 private ExecutorService exec; private ServerSocket server; public static void main(String[] args) { new Server(); } public Server() { try { server = new ServerSocket(PORT); exec = Executors.newCachedThreadPool(); System.out.println("服务器已启动!"); Socket client = null; while (true) { client = server.accept(); // 接收客户连接 list.add(client); exec.execute(new ChatTask(client)); } } catch (IOException e) { e.printStackTrace(); } } static class ChatTask implements Runnable { private Socket socket; private BufferedReader br; private String msg=""; public ChatTask(Socket socket) throws IOException { this.socket = socket; br = new BufferedReader(new InputStreamReader(socket.getInputStream())); } public void run() { new Thread(new Runnable() { public void run() { PrintWriter pw; try { pw = new PrintWriter(socket.getOutputStream(), true); int i = 0; while(true){ i=i+1; msg=i+"\n"; try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } pw.println(msg); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }).start(); } } } 客户端代码: <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" applicationComplete="initApp()"> <fx:Script> <![CDATA[ import flash.net.Socket; import mx.controls.Alert; private var socket:Socket; private function initApp():void { StartTest(); } private function StartTest():void { socket = new Socket("127.0.0.1",3000); // socket.addEventListener(Event.CONNECT, connectHandler); socket.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler); } private function CloseTest():void { if(socket!=null && socket.connected) { trace("socket.connected:"+socket.connected); socket.close(); trace("socket.connected:"+socket.connected); } } // private function connectHandler(event:Event):void // { // trace("connectHandler: " + event); // socket.writeMultiByte(SendStr.text,"GB2312"); // socket.flush(); // } private function socketDataHandler(event:ProgressEvent):void { trace("socketDataHandler: " + event); var str:String=socket.readMultiByte(socket.bytesAvailable,"GB2312"); [color=red]ExternalInterface.call("addValue",str);[/color] // Alert.show(str); // ReceiveStr.text = str; } private function alert():void{ for(var i:int=0;i<10;i++){ ExternalInterface.call("addValue","success!"+i); } } ]]> </fx:Script> <mx:TextArea id="ReceiveStr" x="53" y="68" width="200" height="200"/> <s:Button click="alert()" label="alert"/> </s:Application> jsp代码: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>jsocketTest</title> <script type="text/javascript" src="<%=basePath%>jsocketTest/JSocket/jSocket.js"></script> </head> <body> [color=red]<script type='text/javascript'> function addValue(value) { alert(value); //mySocket.innerText = mySocket.innerText + value; } </script>[/color] <div id='mySocket' /></div> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="100%" height="100%" id="SocketTest"> <param name="movie" value="bin-debug/SocketTest.swf" /> <param name="quality" value="high" /> <param name="bgcolor" value="#ffffff" /> <param name="allowScriptAccess" value="sameDomain" /> <param name="allowFullScreen" value="true" /> <!--[if !IE]>--> <object type="application/x-shockwave-flash" data="bin-debug/SocketTest.swf" width="100%" height="100%"> <param name="quality" value="high" /> <param name="bgcolor" value="#ffffff" /> <param name="allowScriptAccess" value="sameDomain" /> <param name="allowFullScreen" value="true" /> <!--<![endif]--> <!--[if gte IE 6]>--> <p> Either scripts and active content are not permitted to run or Adobe Flash Player version 10.0.0 or greater is not installed. </p> <!--<![endif]--> <a href="http://www.adobe.com/go/getflashplayer"> <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash Player" /> </a> <!--[if !IE]>--> </object> <!--<![endif]--> </object> </body> </html> 我想用java建立tcp/ip服务器然后用flash接受服务器发送的数据,同事将数据发送给js代码然后进一步操作,但是flash单独运行可以接受到服务器的数据,但一旦传给js,js确接不到数据。正常用flash调用js函数还好使,就是flash从服务器接受到的数据在传给js就是显示不出来!帮帮我吧!先谢谢大家了!
tomcat8.exe及tomcat8w.exe无法启动,请问这是怎么回事儿?谢谢
tomcat8解压版,startup.bat可正常启动,eclipse内也可以正常启动 [2013-12-29 19:06:57] [error] ( javajni.c:863 ) [ 6896] FindClass org/apache/catalina/startup/Bootstrap failed [2013-12-29 19:06:57] [error] ( prunsrv.c:1183) [ 7236] Failed to start Java windows不能在本地计算机启动tomcat 错误代码4 不是端口问题、也不是msvcr71.dll文件问题。
Java 如何在建立 Socket 通信后主动向 C#客户端发送信息
使用Java服务器与C#客户端成功建立套接字通信后,Java服务器如何主动向C#客户端发送消息?我只能在成功建立的那一刻向客户发送信息,但这不是我想要的。 项目启动时将开始创建套接字连接,但在建立之后,我无法自己向客户端发送信息。 -----这是负责建立套接字通信的代码。 ``` public void openSocket() throws IOException { Socket socket = null; try { ServerSocket serverSocket = new ServerSocket(5656); log.info("server msg : UnitySocket server start {port : [5656]}"); socket = serverSocket.accept(); log.info("server msg : socket msg [client send !]"); inputStream = new BufferedInputStream(socket.getInputStream()); byte[] out_massage = new byte[messageLengthBytes]; inputStream.read(out_massage); log.info("server msg : client msg is [ "+(new String(out_massage,"utf-8"))); OutputStream outputStream = socket.getOutputStream(); outputStream.write(socket_massage.getBytes()); // socket_massage = "welcome_send_server_!" } catch (IOException e) { e.printStackTrace(); }finally { if(socket != null){ socket.close(); } socket = null; } ``` 这是要发送给客户端的数据 ``` public Boolean askMoveUp(String address, String project, String name, String massage, String startTime, String endTime, String token) throws IOException { StringBuffer stringBuffer = new StringBuffer(); SocketMassage socketMassage = new SocketMassage(); String msg; stringBuffer.append(address).append("_"); stringBuffer.append(project).append("_"); stringBuffer.append(name).append("_"); stringBuffer.append(massage).append("_"); stringBuffer.append(startTime); msg = stringBuffer.toString(); socketMassage.setMsg(msg); return true; } ``` 我想要做的是askMoveUp()方法中的msg数据。如何在openSocket()方法中像socket_massage一样发送给客户端?当项目启动时,socket_massage中的数据被发送到客户端,但msg是如何发送的?希望大家能给我一个帮助,谢谢!
启动jboss报错,在线等!先谢谢各位!
![![图片说明](https://img-ask.csdn.net/upload/201607/10/1468126008_34540.png)图片说明](https://img-ask.csdn.net/upload/201607/10/1468125999_255676.png) 根据wsdl生成的代码服务端只留了一个接口: /** * This class was generated by the JAX-WS RI. * JAX-WS RI 2.2.4-b01 * Generated source version: 2.2 * */ @WebService(name = "BdxmServer", targetNamespace = "http://server.bdxm.dljk.web.ebidding.com.cn/") public interface BdxmServer { /** * * @param cPrice * @param cvalue * @param packageName * @param bidOpenTime * @param biddingTime * @param bidCode * @param packageId * @param bidName * @param bidId * @param packageCode * @return * returns java.lang.String */ @WebMethod @WebResult(name = "getCableInfoResponse", targetNamespace = "") @RequestWrapper(localName = "getCableInfo", targetNamespace = "http://server.bdxm.dljk.web.ebidding.com.cn/", className = "cn.com.ebidding.web.dljk.bdxm.server.GetCableInfo") @ResponseWrapper(localName = "getCableInfoResponse", targetNamespace = "http://server.bdxm.dljk.web.ebidding.com.cn/", className = "cn.com.ebidding.web.dljk.bdxm.server.GetCableInfoResponse") public String getCableInfo( @WebParam(name = "bid_id", targetNamespace = "") String bidId, @WebParam(name = "bid_code", targetNamespace = "") String bidCode, @WebParam(name = "bid_name", targetNamespace = "") String bidName, @WebParam(name = "package_id", targetNamespace = "") String packageId, @WebParam(name = "package_code", targetNamespace = "") String packageCode, @WebParam(name = "package_name", targetNamespace = "") String packageName, @WebParam(name = "bidding_time", targetNamespace = "") String biddingTime, @WebParam(name = "bid_open_time", targetNamespace = "") String bidOpenTime, @WebParam(name = "cvalue", targetNamespace = "") String cvalue, @WebParam(name = "cPrice", targetNamespace = "") String cPrice); } 接口实现类: import javax.jws.WebService; @WebService(endpointInterface="cn.com.ebidding.web.dljk.bdxm.server.BdxmServer", targetNamespace="http://server.bdxm.dljk.web.ebidding.com.cn/", wsdlLocation="MEAT-INF/wsdl/dljk/BdxmServer.wsdl") public class BdxmServerImpl implements BdxmServer { @Override public String getCableInfo(String bidId, String bidCode, String bidName, String packageId, String packageCode, String packageName, String biddingTime, String bidOpenTime, String cvalue, String cPrice) { System.out.println("nidaye"); return "2222222222222222222"; } } wsdl文件: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://server.bdxm.dljk.web.ebidding.com.cn/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="BdxmServerImplService" targetNamespace="http://server.bdxm.dljk.web.ebidding.com.cn/"> <wsdl:types> <xsd:schema targetNamespace="http://server.bdxm.dljk.web.ebidding.com.cn/"> <xsd:element name="getCableInfo"> <!-- <xsd:import namespace="http://www.example.org/BdxmServer/" schemaLocation="BdxmServer.xsd"></xsd:import> --> <xsd:complexType> <xsd:sequence> <xsd:element maxOccurs="1" minOccurs="0" name="bid_id" type="xsd:string"/> <xsd:element maxOccurs="1" minOccurs="0" name="bid_code" type="xsd:string"/> <xsd:element maxOccurs="1" minOccurs="0" name="bid_name" type="xsd:string"/> <xsd:element maxOccurs="1" minOccurs="0" name="package_id" type="xsd:string"/> <xsd:element maxOccurs="1" minOccurs="0" name="package_code" type="xsd:string"/> <xsd:element maxOccurs="1" minOccurs="0" name="package_name" type="xsd:string"/> <xsd:element maxOccurs="1" minOccurs="0" name="bidding_time" type="xsd:string"/> <xsd:element maxOccurs="1" minOccurs="0" name="bid_open_time" type="xsd:string"/> <xsd:element maxOccurs="1" minOccurs="0" name="cvalue" type="xsd:string"/> <xsd:element maxOccurs="1" minOccurs="0" name="cPrice" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="getCableInfoResponse"> <xsd:complexType> <xsd:sequence> <xsd:element name="getCableInfoResponse" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> </wsdl:types> <wsdl:message name="getCableInfo"> <wsdl:part element="tns:getCableInfo" name="getCableInfo"/> </wsdl:message> <wsdl:message name="getCableInfoResponse"> <wsdl:part element="tns:getCableInfoResponse" name="getCableInfoResponse"/> </wsdl:message> <wsdl:portType name="BdxmServer"> <wsdl:operation name="getCableInfo"> <wsdl:input message="tns:getCableInfo"/> <wsdl:output message="tns:getCableInfoResponse"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="BdxmServerSOAP" type="tns:BdxmServer"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="getCableInfo"> <soap:operation soapAction=""/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="BdxmServerImplService"> <wsdl:port binding="tns:BdxmServerSOAP" name="BdxmServerImplPort"> <soap:address location="http://localhost:8088/ebidding/services/BdxmServer/"/> </wsdl:port> </wsdl:service> </wsdl:definitions>
SSH整合时tomcat服务启动不了
启动tomcat 服务时报 严重: Error listenerStart 2009-4-17 15:05:58 org.apache.catalina.core.StandardContext start 严重: Context [/Test] startup failed due to previous errors 的错误 web.xml配置文件如下: <!-- 配置监听器 配置spring配置文件的加载路径 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- OpenSessionInView 延迟加载的问题 --> <filter> <filter-name>OpenSessionInViewFilter</filter-name> <filter-class> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </filter-class> <init-param> <param-name>singleSession</param-name> <param-value>true</param-value> </init-param> </filter> <!-- 配置中文字符问题 --> <filter> <filter-name>charfilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>charfilter</param-name> <param-value>UTF-8</param-value> </init-param> </filter> ------------------------------------------------------------------------------------------------- struts-config.xml配置文件如下: <!-- 配置将struts 自动创建的action交给spring处理 --> <controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"> </controller> ------------------------------------------------------------------------------------------------- applicationContext.xml配置文件如下: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd "> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"></property> <property name="url" value="jdbc:sqlserver://localhost:1433;databaseName=testdb"></property> <property name="username" value="sa"></property> <property name="password" value="123456"></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop> </props> </property> <property name="mappingResources"> <list> <value>com/svse/entity/Student.hbm.xml</value> <value>com/svse/entity/Class.hbm.xml</value> <value>com/svse/entity/Studentinfo.hbm.xml</value> <value>com/svse/entity/Classinfo.hbm.xml</value></list> </property></bean> <bean id="StudentinfoDAO" class="com.svse.dao.StudentinfoDAO"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <bean id="ClassinfoDAO" class="com.svse.dao.ClassinfoDAO"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <!-- 配置业务层 impl --> <bean id="StudnetImpl" class="com.svse.impl.StudentImpl"> <property name="studao"> <ref bean="StudentinfoDAO"/> </property> </bean> <bean id="ClassImpl" class="com.svse.impl.ClassImpl"> <property name="classdao"> <ref bean="ClassinfoDAO"/> </property> </bean> <!-- 配置action --> <!-- 配置事务 --> <!-- 配置hibernate事务管理器 --> <bean id="MyTrans" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref bean="sessionFactory"/> </property> </bean> <!-- 配置事务特性 --> <tx:advice id="tx1" transaction-manager="MyTrans"> <tx:attributes> <tx:method name="add*" propagation="REQUIRED"/> <tx:method name="del*" propagation="REQUIRED"/> <tx:method name="update*" propagation="REQUIRED"/> <tx:method name="*" read-only="true"/> </tx:attributes> </tx:advice> <!-- 使用aop 注入 --> <aop:config> <aop:pointcut id="p1" expression="execution(* com.svse.impl.*.*(..))"/> <aop:advisor advice-ref="tx1" pointcut-ref="p1"/> </aop:config> </beans> --------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------- 配置文件信息跟上个练习的项目中无差别,上个项目中也出现过这个文件,但忘了怎么解决的。请老鸟解决下下,谢谢咯 [b]问题补充:[/b] 恩,1楼,把你说的那段代码去掉后不报错。但后面肯定要用到这的,请帮忙解决 [b]问题补充:[/b] java.lang.ClassNotFoundException: org.springframework.scripting.config.LangNamespaceHandler at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1359) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1205) at org.springframework.util.ClassUtils.forName(ClassUtils.java:229) at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.initHandlerMappings(DefaultNamespaceHandlerResolver.java:117) at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.<init>(DefaultNamespaceHandlerResolver.java:96) at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.<init>(DefaultNamespaceHandlerResolver.java:83) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.createDefaultNamespaceHandlerResolver(XmlBeanDefinitionReader.java:498) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.createReaderContext(XmlBeanDefinitionReader.java:487) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:468) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:363) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:313) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:290) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:131) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:147) at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124) at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:92) at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:101) at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:389) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:324) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:245) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:188) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3764) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4216) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920) at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022) at org.apache.catalina.core.StandardHost.start(StandardHost.java:736) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) at org.apache.catalina.core.StandardService.start(StandardService.java:448) at org.apache.catalina.core.StandardServer.start(StandardServer.java:700) at org.apache.catalina.startup.Catalina.start(Catalina.java:552) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433) (4219 ms) [main] DEBUG: org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver#initHandlerMappings : Ignoring namespace handler [org.springframework.ejb.config.JeeNamespaceHandler]: handler class not found java.lang.ClassNotFoundException: org.springframework.ejb.config.JeeNamespaceHandler at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1359) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1205) at org.springframework.util.ClassUtils.forName(ClassUtils.java:229) at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.initHandlerMappings(DefaultNamespaceHandlerResolver.java:117) at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.<init>(DefaultNamespaceHandlerResolver.java:96) at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.<init>(DefaultNamespaceHandlerResolver.java:83) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.createDefaultNamespaceHandlerResolver(XmlBeanDefinitionReader.java:498) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.createReaderContext(XmlBeanDefinitionReader.java:487) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:468) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:363) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:313) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:290) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:131) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:147) at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124) at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:92) at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:101) at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:389) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:324) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:245) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:188) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3764) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4216) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920) at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022) at org.apache.catalina.core.StandardHost.start(StandardHost.java:736) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) at org.apache.catalina.core.StandardService.start(StandardService.java:448) at org.apache.catalina.core.StandardServer.start(StandardServer.java:700) at org.apache.catalina.startup.Catalina.start(Catalina.java:552) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433) [b]问题补充:[/b] 自动代理的bean?我先前练习的好像也是这样陪的 [b]问题补充:[/b] 还有这个 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [com/svse/entity/Student.hbm.xml] cannot be opened because it does not exist Caused by: java.io.FileNotFoundException: class path resource [com/svse/entity/Student.hbm.xml] cannot be opened because it does not exist at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:135) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:656) at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:134) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1198) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1167) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:427) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:285) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:245) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:188) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3764) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4216) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920) at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022) at org.apache.catalina.core.StandardHost.start(StandardHost.java:736) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) at org.apache.catalina.core.StandardService.start(StandardService.java:448) at org.apache.catalina.core.StandardServer.start(StandardServer.java:700) at org.apache.catalina.startup.Catalina.start(Catalina.java:552) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433) (5938 ms) [main] ERROR: org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/Test]#listenerStart : Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [com/svse/entity/Student.hbm.xml] cannot be opened because it does not exist Caused by: java.io.FileNotFoundException: class path resource [com/svse/entity/Student.hbm.xml] cannot be opened because it does not exist at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:135) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:656) at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:134) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1198) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1167) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:427) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:285) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:245) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:188) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3764) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4216) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920) at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022) at org.apache.catalina.core.StandardHost.start(StandardHost.java:736) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) at org.apache.catalina.core.StandardService.start(StandardService.java:448) at org.apache.catalina.core.StandardServer.start(StandardServer.java:700) at org.apache.catalina.startup.Catalina.start(Catalina.java:552) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433) [b]问题补充:[/b] 有这个包,不少 [b]问题补充:[/b] spring包已经截图 [b]问题补充:[/b] 你说说包的名字吧。 你刚才说的那个包确实有, 要不我直接把项目打包发你给我看看? [b]问题补充:[/b] 我想问下 我的entity 里的配置文件名字是 Studentinfo.hbm.xml 他怎么报 java.io.FileNotFoundException: class path resource [com/svse/entity/Student.hbm.xml] cannot be opened because it does not exist Caused by: java.io.FileNotFoundException: class path resource [com/svse/entity/Student.hbm.xml] cannot be opened because it does not exist 的错误 [b]问题补充:[/b] 问题已解决,就是因为sessionfactory那个bean下有个student。hbm。xml的原因 谢谢你lovewhzlq (资深程序员)
Linux下eclipse启动问题
VMware10.0.1安装了RedHat linux 9.0,JDK装的是1.6.0.45(i586),输入java -version 显示正常,说明配置没问题,但是eclipse启动时候就奔溃了,具体奔溃信息如下,麻烦各位大神看看,因为是学习需要,老师布置的作业,要读操作系统代码,第一次用linux,后生谢谢了 A fatal error has been detected by the Runtime Environment: SIGFPE(0x8) at pc=0x40008d7c,pid=4440,tid=1073951360 JRE version:6.0_45-b06 Java VN:Java HotSpot(TM) Client VM (20.45-b01 mixed mode,shape linux-x86) problemmatic frame: C[ld-linux.so.2+0x8d7c] double+0x9c the crash happened outside the java virtual machine in native code see problematic frame for where to report the bug
切换Activity时报错Unable to stop activity
请教一下大家,哪些原因可能导致下面出现的问题! 程序有两个Activity,从MainActivity启动到NoteActivity时报错,主要是说`java.lang.RuntimeException: Unable to stop activity {<包名>/<包名>.MainActivity}: java.lang.NullPointerException`和`Caused by: java.lang.NullPointerException`,日志里没有说我的代码哪行有问题,都是些系统自己的类和方法。 两个Activity的声明: ```XML <activity android:name=".activity.MainActivity" android:theme="@style/AppTheme.NoActionBar"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".activity.NoteActivity" android:theme="@style/AppTheme.NoActionBar" /> ``` 启动NoteActivity的代码: ```Java FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab_new_note); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(MainActivity.this, NoteActivity.class); intent.putExtra("Open_Type", "newNote"); startActivity(intent); } }); ``` 点了fab按钮后直接报错,完整的错误日志如下: ``` E/AndroidRuntime: FATAL EXCEPTION: main Process: zqy.bysj.todo, PID: 2034 java.lang.RuntimeException: Unable to stop activity {zqy.bysj.todo/zqy.bysj.todo.activity.MainActivity}: java.lang.NullPointerException at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3174) at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3220) at android.app.ActivityThread.access$1100(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1223) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5001) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at android.app.Activity.performStop(Activity.java:5388) at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3171) at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3220)  at android.app.ActivityThread.access$1100(ActivityThread.java:135)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1223)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:136)  at android.app.ActivityThread.main(ActivityThread.java:5001)  at java.lang.reflect.Method.invokeNative(Native Method)  at java.lang.reflect.Method.invoke(Method.java:515)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)  at dalvik.system.NativeStart.main(Native Method)  ``` 请教一下大家,哪些原因可能导致这个问题?谢谢! 附图,看的清楚点。 ![图片说明](https://img-ask.csdn.net/upload/201703/14/1489458992_581817.png)
javaservice将jar包制作成windows服务,可以安装,但是无法启动
最近有个需求,就是写个windows服务部署到内网,每天不断的对数据库查询对哪些满足条件的用户发送短信。我使用的是spring+mybatis,使用maven管理jar包。我实现了第一步:将maven项目打成jar包,然后直接使用java -jar xxx.jar测试运行jar包,发现是可以成功运行的。 然后我使用了javaservice将jar包制作成windows服务,安装成功。但是不论是在cmd中使用net start ServiceName 还是到服务列表手动启动,都不能启动,百度了好久,也换过代码甚至工具,都是可以安装成功,启动失败,如下图所示。所以在这里向大家求助,希望大神们指点迷津 ,谢谢。 基本信息: maven工程 框架 spring+mybatis 入口 一个main方法 使用线程+while(true)不间断执行 ![图片说明](https://img-ask.csdn.net/upload/201709/08/1504861317_306286.png)
Java Swing可运行的jar双击启动不能保存文件
各位,最近用NetBeans做一个Java Swing项目,但是于到了这样一个奇怪的问题。我的代码里有一段用FileOutputStream来写文件的代码,如果在命令行上用java -jar方式运行,那么不会有任何问题,文件可以被正常的写入。但是如果双击.jar文件运行的话,程序也不会报错,但是就是找不到那个用FileOutputStream生成的文件……这是什么原因呀?我在程序后面也加上了flush(),也试过了close(),但是还是这个情况,有点不解…… 谢谢大家了:-)
springcloud zookeeper注册中心,在客服端用restTemplate 访问,第一次访问正常,第二次以后都是失败
springcloud zookeeper注册中心,在客服端用restTemplate 访问,第一次访问正常,第二次以后都是失败: 配置以及主要代码如下: 服务端: ``` 配置: server.port=8082 spring.application.name=service-zookeeper spring.cloud.zookeeper.discovery.register=true spring.cloud.zookeeper.discovery.enabled=true spring.cloud.zookeeper.discovery.root=/spring-cloud-service spring.cloud.zookeeper.connect-string=cdh01.com:2181,cdh02.com:2181,cdh03.com:2181 java: @RequestMapping(value ="/index") @ResponseBody public AjaxView index(@RequestBody String jsoninfo,HttpServletRequest request, HttpServletResponse response){ 。。。 } ``` 客户端: ``` server.port=8081 spring.application.name=getway-zookeeper spring.cloud.zookeeper.discovery.register=false spring.cloud.zookeeper.discovery.enabled=true spring.cloud.zookeeper.discovery.root=/spring-cloud-service spring.cloud.zookeeper.connect-string=cdh01.com:2181,cdh02.com:2181,cdh03.com:2181 spring.cloud.zookeeper.dependencies.service-zookeeper.required=true spring.cloud.zookeeper.dependencies.service-zookeeper.path=/service-zookeeper spring.cloud.zookeeper.dependencies.service-zookeeper.loadBalancerType=ROUND_ROBIN feign.hystrix.enabled=true ``` JAVA代码: ``` @RequestMapping(value ="/api/{service_name}/{interface_name}") @ResponseBody public String getApiSend( @RequestBody String jsoninfo, @PathVariable String service_name, @PathVariable String interface_name) { String get_url ="http://"+service_name+"/"+interface_name; return backService.getApiSend(jsoninfo,get_url); } ``` 都启动成功后,第一次访问正常,第二次访问就报错了,报错提示没有找到服务列表,但是服务列表确实打印出来了。如下: No up servers available from load balancer ,因为这个提示,没有服务,后续就报错空指针了。但是确实有服务查询到。而且DEBUG也打印出来了。 ``` 2019-05-19 14:37:55.547 WARN 164828 --- [nio-8081-exec-9] com.netflix.loadbalancer.RoundRobinRule : No up servers available from load balancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=service-zookeeper,current list of Servers=[zhucj:8082],Load balancer stats=Zone stats: {unknown=[Zone:unknown; Instance count:1; Active connections count: 0; Circuit breaker tripped count: 0; Active connections per server: 0.0;] },Server stats: [[Server:zhucj:8082; Zone:UNKNOWN; Total Requests:0; Successive connection failure:0; Total blackout seconds:0; Last connection made:Thu Jan 01 08:00:00 CST 1970; First connection made: Thu Jan 01 08:00:00 CST 1970; Active Connections:0; total failure count in last (1000) msecs:0; average resp time:0.0; 90 percentile resp time:0.0; 95 percentile resp time:0.0; min resp time:0.0; max resp time:0.0; stddev resp time:0.0] ]}ServerList:org.springframework.cloud.zookeeper.discovery.ZookeeperServerList@28667be9 [DEBUG][2019/05/1914:37:55549 ][org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:136)] Resolving exception from handler [public java.lang.String com.example.demo.controller.PageController.getApiSend(java.lang.String,java.lang.String,java.lang.String)]: java.lang.NullPointerException [DEBUG][2019/05/1914:37:55552 ][org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:136)] Resolving exception from handler [public java.lang.String com.example.demo.controller.PageController.getApiSend(java.lang.String,java.lang.String,java.lang.String)]: java.lang.NullPointerException [DEBUG][2019/05/1914:37:55555 ][org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:136)] Resolving exception from handler [public java.lang.String com.example.demo.controller.PageController.getApiSend(java.lang.String,java.lang.String,java.lang.String)]: java.lang.NullPointerException [DEBUG][2019/05/1914:37:55558 ][org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:993)] Could not complete request java.lang.NullPointerException at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:192) at com.google.common.cache.LocalCache.get(LocalCache.java:3931) at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3936) at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4806) at com.netflix.loadbalancer.LoadBalancerStats.getServerStats(LoadBalancerStats.java:175) at com.netflix.loadbalancer.LoadBalancerStats.getSingleServerStat(LoadBalancerStats.java:362) at com.netflix.loadbalancer.AvailabilityPredicate.apply(AvailabilityPredicate.java:73) at com.netflix.loadbalancer.AvailabilityPredicate.apply(AvailabilityPredicate.java:35) at com.netflix.loadbalancer.CompositePredicate.apply(CompositePredicate.java:52) at com.netflix.loadbalancer.CompositePredicate.apply(CompositePredicate.java:40) at com.netflix.loadbalancer.AvailabilityFilteringRule.choose(AvailabilityFilteringRule.java:86) at org.springframework.cloud.zookeeper.discovery.dependency.DependenciesBasedLoadBalancer.chooseServer(DependenciesBasedLoadBalancer.java:64) at org.springframework.cloud.zookeeper.discovery.dependency.DependencyRibbonAutoConfiguration$1.chooseServerByServiceIdOrDefault(DependencyRibbonAutoConfiguration.java:72) at org.springframework.cloud.zookeeper.discovery.dependency.DependencyRibbonAutoConfiguration$1.getServer(DependencyRibbonAutoConfiguration.java:65) at org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.choose(RibbonLoadBalancerClient.java:76) at org.springframework.cloud.client.loadbalancer.InterceptorRetryPolicy.canRetry(InterceptorRetryPolicy.java:53) at org.springframework.retry.support.RetryTemplate.canRetry(RetryTemplate.java:375) at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:278) at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:180) at org.springframework.cloud.client.loadbalancer.RetryLoadBalancerInterceptor.intercept(RetryLoadBalancerInterceptor.java:67) at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:92) at org.springframework.cloud.zookeeper.discovery.dependency.DependencyRestTemplateAutoConfiguration$1.intercept(DependencyRestTemplateAutoConfiguration.java:67) at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:92) at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:76) at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48) at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53) at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:723) at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:680) at org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:466) at com.example.demo.util.WebUtil.SendPost(WebUtil.java:86) at com.example.demo.service.BackService.getApiSend(BackService.java:18) at com.example.demo.controller.PageController.getApiSend(PageController.java:60) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:877) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:783) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:877) at javax.servlet.http.HttpServlet.service(HttpServlet.java:648) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:158) at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:126) at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:111) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter.doFilterInternal(HttpTraceFilter.java:90) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1468) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) [DEBUG][2019/05/1914:37:55574 ][org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:104)] Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@46dfd3ba 2019-05-19 14:37:55.585 ERROR 164828 --- [nio-8081-exec-9] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause ``` 请帮忙看看,谢谢。
java 关于NIO实现UDP数据传输问题 ,急谢谢,C币不足请不要介意
各位大侠好,小弟想问一下问题,搞了一两天没有搞明白的。因为要实现一个UDP传输服务端,于是在网上找了很多资料然后就写了一个。但是写好之后发现有两个很严重的问题,希望各位大哥给点意见或者思路去解决。 问题一:启动服务端,同时也启动客户端,客户端传输数据服务器正常接收,但是断开客户端后,再启动客户端,服务器就收不到任何客户端发送的消息,好像是服务器关闭了UDP一样,但是重启服务器后(重新打开UDP)客户端既可以发送信息过来。 问题二:多个客户端。第一个客户端连接上后,第二个客户端怎么也链接不上了。即使关闭了第一个客户端也一样。 如下是代码: package com.gateway.socket; import java.io.IOException; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.net.UnknownHostException; import java.nio.ByteBuffer; import java.nio.channels.DatagramChannel; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; import java.util.Iterator; import java.util.Set; import org.apache.log4j.Logger; public class UDPEchoServerSelector extends Thread { private static final Logger log = Logger.getLogger(ServerSocket.class); // private InetSocketAddress inetSocketAddress; // socket处理类 private UDPSocketHandler handler = new UDPSocketHandler(); // 注册的接受服务 private SocketReceiver receiver = null; /** * 初始化socket * * @param receiver * @param hostname * @param port * @throws IOException * @throws UnknownHostException */ public UDPEchoServerSelector(SocketReceiver receiver, String hostname, int port) { if (hostname.isEmpty()) { inetSocketAddress = new InetSocketAddress(port); } else { inetSocketAddress = new InetSocketAddress(hostname, port); } this.receiver = receiver; } @Override public void run() { try { Selector selector = Selector.open(); // 创建选择器,可以处理多路通道。 DatagramChannel serverSocketChannel = DatagramChannel.open(); // 打开通道 serverSocketChannel.configureBlocking(false); // 非阻塞 serverSocketChannel.socket().bind(inetSocketAddress); /* * 将通道管理器和该通道绑定,并为该通道注册SelectionKey.OP_READ事件,注册该事件后, * 当该事件到达时,selector.select()会返回,如果该事件没到达selector.select()会一直阻塞。 */ serverSocketChannel.register(selector, SelectionKey.OP_READ, new ClientData()); log.info("Server: socket server started."); /* * 采用轮询的方式监听selector上是否有需要处理的事件,如果有,则进行处理 */ while (true) { // 轮询 // 当注册的事件到达时,方法返回;否则,该方法会一直阻塞 int nKeys = selector.select(); if (nKeys == 0) { continue; } // 得到选择键列表 Set Keys = selector.selectedKeys(); Iterator it = Keys.iterator(); while (it.hasNext()) { SelectionKey key = null; key = (SelectionKey) it.next(); // 键为位掩码 it.remove(); // 客户端请求连接事件 if (key.isValid() && key.isWritable()) { log.info("Server: SelectionKey is acceptable."); handler.handleWrite(key); } if (key.isReadable()) {// 获得了可读的事件 log.info("Server: SelectionKey is readable."); handler.receiveMsg(key, receiver); } } Keys.clear(); } } catch (IOException e) { e.printStackTrace(); } } public static class ClientData { public SocketAddress clientAddress; public ByteBuffer buffer = ByteBuffer.allocate(255); } } package com.gateway.socket; import java.io.IOException; import java.net.InetSocketAddress; import java.nio.ByteBuffer; import java.nio.channels.DatagramChannel; import java.nio.channels.SelectionKey; import org.apache.log4j.Logger; import com.gateway.common.DeviceDataTools; import com.gateway.common.data.HexUtils; import com.gateway.socket.UDPEchoServerSelector.ClientData; /** * * 处理socket类 * * @author Andy * */ public class UDPSocketHandler { private static Logger log = Logger.getLogger(UDPSocketHandler.class); /** * 链接请求 * * @throws IOException */ public void handleWrite(SelectionKey key) { try { DatagramChannel channel = (DatagramChannel) key.channel(); ClientData clntDat = (ClientData) key.attachment(); clntDat.buffer.flip(); // 从起始位置开始发送 int bytesSent; bytesSent = channel.send(clntDat.buffer, clntDat.clientAddress); if (bytesSent != 0) { key.interestOps(SelectionKey.OP_READ); // 关注客户端发送数据 } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * 读请求 * * @throws IOException */ public void receiveMsg(SelectionKey key, SocketReceiver receiver) { ByteBuffer byteBuffer = ByteBuffer.allocate(1024); byteBuffer.clear(); DatagramChannel socketChannel = (DatagramChannel) key.channel(); //非阻塞 try { socketChannel.configureBlocking(false); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } System.out.println("channel code:" + socketChannel.hashCode()); try { while (true) { InetSocketAddress client = (InetSocketAddress) socketChannel .receive(byteBuffer); byteBuffer.flip(); // byteBuffer中传过来的是10进制的bytep[] byte[] dst = new byte[byteBuffer.limit()]; byteBuffer.get(dst); // 将10进制的byte[]转化成16进制字符串 String data = HexUtils.converBytesToHex(dst); System.out.println(data); log.info("Server: data1 = " + data); byteBuffer.clear(); receiver.udpreceive(socketChannel, data, client); break; } } catch (java.io.IOException e) { //e.printStackTrace(); //this.closeChannel(key, socketChannel); } catch (Exception e) { //e.printStackTrace(); //this.closeChannel(key, socketChannel); } } /** * * @param socketChannel */ private void closeChannel(SelectionKey key, DatagramChannel socketChannel) { try { while (socketChannel.isOpen()) { key.cancel(); socketChannel.close(); } } catch (IOException e1) { e1.printStackTrace(); } } /** * 根据socketKey从内存中获取channel,通过channel向client端发送消息 * * @param socketKey * 内存在channel对应的key * @param data * 发送的数据 * @return * @throws IOException */ public static boolean send(String socketKey, String data) throws IOException { DatagramChannel socketChannel = SocketChannelMapper .getUDPChannel(socketKey); if (socketChannel == null || !socketChannel.isOpen()) { return false; } InetSocketAddress client = SocketChannelMapper .getUDPInetSocketAddress(socketKey + "address"); boolean f = socketChannel.isConnected(); ByteBuffer byteBuffer = ByteBuffer.wrap(DeviceDataTools.hex2Byte(data)); if (f) { socketChannel.write(byteBuffer); } else { socketChannel.connect(new InetSocketAddress(client.getAddress(), client.getPort())); socketChannel.send(byteBuffer, client); } return true; } /** * 根据socketKey从内存中获取channel,通过channel向client端发送消息 * * @param socketKey * 内存在channel对应的key * @param data * 发送的数据 * @return * @throws IOException */ public static boolean send(DatagramChannel socketChannel, String data, InetSocketAddress client) throws IOException { if (socketChannel == null) { return false; } System.out.println("#########################ADDRESS" + client.getAddress()); System.out.println("#########################PORT" + client.getPort()); boolean f = socketChannel.isConnected(); ByteBuffer byteBuffer = ByteBuffer.wrap(DeviceDataTools.hexStr2ByteArray(data)); if (f) { socketChannel.write(byteBuffer); } else { socketChannel.connect(new InetSocketAddress(client.getAddress(), client.getPort())); socketChannel.send(byteBuffer, client); } return true; } }
slf4j包的问题
[code="java"]java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V at org.apache.commons.logging.impl.SLF4JLocationAwareLog.info(SLF4JLocationAwareLog.java:159) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:273) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4797) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1114) at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1673) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619)[/code] 新人,公司的项目,从svn中checkout下来部署到tomcat后启动服务就报这个错,我对代码不熟悉,有人遇到过这个问题吗?求解答,谢谢!
困扰了一整天的bug,求帮助,
我最近在用Maven做一个Javaweb项目,但是今天碰到了一个问题,我复制了报错信息百度搜索,上csdn,stackoverflow,等网站都没有找到解决的方法,我感觉是数据库的问题,但是我尝试过用JDBC来操作数据库,可以正常连接。 数据库账号密码我确认过没有错误,我是跟着视频学的,刚刚接触java不久,希望能够得到大神的帮助,感激不尽 全部报错信息如下: ``` java.lang.NullPointerException at java.util.Properties$LineReader.readLine(Properties.java:434) at java.util.Properties.load0(Properties.java:353) at java.util.Properties.load(Properties.java:341) at cn.itcast.travel.util.JDBCUtils.<clinit>(JDBCUtils.java:31) at cn.itcast.travel.dao.impl.UserDaoImpl.<init>(UserDaoImpl.java:10) at cn.itcast.travel.service.impl.UserServiceImpl.<init>(UserServiceImpl.java:9) at cn.itcast.travel.web.servlet.RegistUserServlet.doPost(RegistUserServlet.java:35) at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) 六月 21, 2019 10:40:52 下午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet [cn.itcast.travel.web.servlet.RegistUserServlet] in context with path [/travel] threw exception java.lang.IllegalArgumentException: Property 'dataSource' is required at org.springframework.jdbc.support.JdbcAccessor.afterPropertiesSet(JdbcAccessor.java:135) at org.springframework.jdbc.core.JdbcTemplate.<init>(JdbcTemplate.java:169) at cn.itcast.travel.dao.impl.UserDaoImpl.<init>(UserDaoImpl.java:10) at cn.itcast.travel.service.impl.UserServiceImpl.<init>(UserServiceImpl.java:9) at cn.itcast.travel.web.servlet.RegistUserServlet.doPost(RegistUserServlet.java:35) at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) ``` 各位,我把项目上传到了百度云,里面的代码我都已经写好了,只要启动项目,在注册页面上填写注册信息,点击提交,控制台就会报错。数据库的代码就在项目的travel.sql文件中, 感兴趣有时间的可以帮忙看一下我代码究竟那里出错了,不感兴趣的可以忽略这段话,如果不是实在没有头绪,我也不会做伸手党,这已经是第二天了,今天在解决不了,就要跳过项目学框架了。谢谢各位啦 链接:https://pan.baidu.com/s/1KImj8iaxV9xy-cv5ri0LXg 提取码:fzwk 复制这段内容后打开百度网盘手机App,操作更方便哦
Tomcat启动时的问题
<p>本地开发环境Tomcat5+jdk1.4</p> <p>服务器环境  Tomcat5.5+jdk1.5</p> <p>代码在本地运行无异常,编译之后放到服务器上,启动Tomcat的时候报错.......无语了</p> <p>2010-06-29 09:45:17-[ERROR]-Context initialization failed<br>org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [com.ccit.csm.preaccepted.dao.impl.BBLinodeQueryOrderDaoImpl] for bean with name 'bbLinodeQueryOrderDao' defined in class path resource [com/ccit/csm/preaccepted/daoContext-preaccepted.xml]: problem with class file or dependent class; nested exception is java.lang.ClassFormatError: com/ccit/csm/preaccepted/dao/BBLinodeQueryOrderDao (Extra bytes at the end of the class file)<br>Caused by: <br>java.lang.ClassFormatError: com/ccit/csm/preaccepted/dao/BBLinodeQueryOrderDao (Extra bytes at the end of the class file)<br>        at java.lang.ClassLoader.defineClass0(Native Method)<br>        at java.lang.ClassLoader.defineClass(ClassLoader.java:539)<br>        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)<br>        at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1634)<br>        at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:860)<br>        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1307)<br>        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1189)<br>        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)<br>        at java.lang.ClassLoader.defineClass0(Native Method)<br>        at java.lang.ClassLoader.defineClass(ClassLoader.java:539)<br>        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)<br>        at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1634)<br>        at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:860)<br>        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1307)<br>        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1189)<br>        at org.springframework.util.ClassUtils.forName(ClassUtils.java:201)<br>        at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:327)<br>        at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1066)<br>        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:282)<br>        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)<br>        at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:156)<br>        at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)<br>        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)<br>        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)<br>        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)<br>        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4343)<br>        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:823)<br>        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:807)<br>        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:595)<br>        at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDeployer.java:277)<br>        at org.apache.catalina.core.StandardHost.install(StandardHost.java:832)<br>        at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:701)<br>        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:432)<br>        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:983)<br>        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:349)<br>        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)<br>        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1091)<br>        at org.apache.catalina.core.StandardHost.start(StandardHost.java:789)<br>        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)<br>        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478)<br>        at org.apache.catalina.core.StandardService.start(StandardService.java:480)<br>        at org.apache.catalina.core.StandardServer.start(StandardServer.java:2313)<br>        at org.apache.catalina.startup.Catalina.start(Catalina.java:556)<br>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<br>        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br>        at java.lang.reflect.Method.invoke(Method.java:324)<br>        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:287)<br>        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:425)<br>2010-6-29 9:45:17 org.apache.catalina.core.StandardContext start<br>严重: Error listenerStart</p> <p> </p> <p>谢谢了</p>
java socket 长连接奇怪的问题
我有一个类,负责通过SOCKET长连接与服务器端通讯。 这个循环读取一个队列来发送。 问题来了,在本类的MAIN方法中向队列中添加数据,就可以发送出去,在SERVLET中,通过HTTP请求添加,就是发送不出去!请大家帮忙看看,谢谢。下面是这个主要类的代码。 /** * */ package com.dianshangwang.lianhepayfront.service; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketException; import java.util.HashMap; import java.util.LinkedList; import java.util.Map; import java.util.Queue; import org.apache.log4j.BasicConfigurator; import org.apache.log4j.Logger; import com.dianshangwang.lianhepayfront.global.Config; import com.google.gson.JsonObject; import com.google.gson.JsonParser; /** * @author lay * @date 2013年11月4日 */ public class IcardpayClient { private static Logger log = Logger.getLogger(IcardpayClient.class); private static Socket socket; private static BufferedReader reader; private static PrintWriter writer; private static Thread sendThread; private static Thread receiveThread; private static Thread monitorThread; private static boolean isRunning = false; /** * 心跳计数器 若此值与当前时间戳值小于60000则认定断线,进行重联操作 */ private static Long heartbeatTimestamp = System.currentTimeMillis(); private static IcardpayClient instance = new IcardpayClient(); private IcardpayClient() { } public static IcardpayClient getInstance() { return instance; } public static void main(String[] args) { BasicConfigurator.configure(); IcardpayClient client = new IcardpayClient(); client.start(); MsgQueue.sendQueue.add("{\"agentNo\":\"A10342hp\",\"tradeType\":\"256\",\"sessionId\":\"1\"}"); } public void start() { init(); sendThread = new Thread(new SendThread());// 启动读线程 receiveThread = new Thread(new ReceiveThread());// 启动收线程 monitorThread = new Thread(new MonitorThread()); // 启动监视线程 sendThread.setName("icardpay-send-thread"); receiveThread.setName("icardpay-receive-thread"); monitorThread.setName("icardpay-monitor-thread"); // sendThread.setDaemon(true); // receiveThread.setDaemon(true); // monitorThread.setDaemon(true); sendThread.start(); log.info("SOCKET发送线程开启!"); receiveThread.start(); log.info("SOCKET接收线程开启!"); // monitorThread.start(); // log.info("SOCKET监视线程开启!"); } public void restart() { stop(); init(); } public void stop() { isRunning = false; } private void init() { socket = new Socket(); try { socket.setKeepAlive(true); socket.connect(new InetSocketAddress(Config.icardpayHost, Config.icardpayPort)); reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8")); writer = new PrintWriter(socket.getOutputStream()); heartbeatTimestamp = System.currentTimeMillis(); log.info("已创建与支付通的SOCKET连接!"); isRunning = true; } catch (SocketException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void write(String msg) { writer.println(msg); writer.flush(); log.info(Thread.currentThread().getName() + "发送:" + msg); } private String read() throws IOException { String msg = reader.readLine(); if (msg != null) { log.info("接收:" + msg); } return msg; } class SendThread implements Runnable { @Override public void run() { while (isRunning) { if (!MsgQueue.sendQueue.isEmpty()) { String v = MsgQueue.sendQueue.poll(); write(v); } try { Thread.sleep(300); } catch (InterruptedException e) { e.printStackTrace(); } } } } class ReceiveThread implements Runnable { @Override public void run() { while (isRunning) { String content = null; try { content = read(); } catch (IOException e1) { log.error("SOCKET读取异常,将重新启动。。。", e1); restart(); continue; } if (null == content || content == "") { continue; } JsonObject obj = new JsonParser().parse(content).getAsJsonObject(); if (obj.has("tradeType") && "0".equals(obj.get("tradeType").getAsString())) { // 收到心跳包, 刷新计数器 heartbeatTimestamp = System.currentTimeMillis(); continue; } if (!obj.has("sessionId")) { log.info("收到未标识的包:" + obj.toString()); continue; } String id = obj.get("sessionId").getAsString(); if (MsgQueue.listeners.containsKey(id)) { MsgQueue.listeners.get(id).received(content); MsgQueue.listeners.remove(id); } else { log.info("接收到过期包:" + content); } try { Thread.sleep(100); } catch (InterruptedException e) { // 忽略 } } } } class MonitorThread implements Runnable { String heartbeat = "{\"agentNo\":\"A10342hp\",\"tradeType\":\"0\"}"; @Override public void run() { while (isRunning) { if (System.currentTimeMillis() - heartbeatTimestamp >= 60000) { // SOCKET已失效 restart(); } // 发送心跳包 write(heartbeat); try { Thread.sleep(5000); } catch (InterruptedException e) { // 忽略 } } } } }
class file editor source not found
tomcat 启动时控制台输出的: 信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.6.0_39\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\Java\jdk1.6.0_39\jre\bin;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:/Program Files/Java/jre6/lib/i386;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Java\jdk1.6.0_39bin;C:\eclipse;;.2015-1-11 23:11:50 org.apache.coyote.http11.Http11Protocol init2015-1-11 23:11:51 org.apache.catalina.loader.WebappClassLoader validateJarFile 信息: validateJarFile(D:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\OrderSystem\WEB-INF\lib\javaee_no_persistence.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class Action :List userList =userService.getUserList(); 执行这句是报:class file editor source not found 根据代码提示: throw new IllegalArgumentException("The " + methodName + "() is not defined in action " + getAction().getClass() + ""); 请高手详细点指点....谢谢
it doesn't contain soffice.bin: F:\openoffice
用jodconverter启动openoffice时 报 invalid officeHome: it doesn't contain soffice.bin: F:\openoffice 启动代码如下,有那么大神可以帮我解答哈谢谢 /** * 连接OpenOffice.org 并且启动OpenOffice.org * * @return */ public OfficeManager getOfficeManager() { DefaultOfficeManagerConfiguration config = new DefaultOfficeManagerConfiguration(); // 获取OpenOffice.org 3的安装目录 String officeHome = "F:\\openoffice"; config.setOfficeHome(officeHome); // 启动OpenOffice的服务 OfficeManager officeManager = config.buildOfficeManager(); officeManager.start(); return officeManager; }
相见恨晚的超实用网站
搞学习 知乎:www.zhihu.com 简答题:http://www.jiandati.com/ 网易公开课:https://open.163.com/ted/ 网易云课堂:https://study.163.com/ 中国大学MOOC:www.icourse163.org 网易云课堂:study.163.com 哔哩哔哩弹幕网:www.bilibili.com 我要自学网:www.51zxw
花了20分钟,给女朋友们写了一个web版群聊程序
参考博客 [1]https://www.byteslounge.com/tutorials/java-ee-html5-websocket-example
爬虫福利二 之 妹子图网MM批量下载
爬虫福利一:27报网MM批量下载    点击 看了本文,相信大家对爬虫一定会产生强烈的兴趣,激励自己去学习爬虫,在这里提前祝:大家学有所成! 目标网站:妹子图网 环境:Python3.x 相关第三方模块:requests、beautifulsoup4 Re:各位在测试时只需要将代码里的变量 path 指定为你当前系统要保存的路径,使用 python xxx.py 或IDE运行即可。
字节跳动视频编解码面经
引言 本文主要是记录一下面试字节跳动的经历。 三四月份投了字节跳动的实习(图形图像岗位),然后hr打电话过来问了一下会不会opengl,c++,shador,当时只会一点c++,其他两个都不会,也就直接被拒了。 七月初内推了字节跳动的提前批,因为内推没有具体的岗位,hr又打电话问要不要考虑一下图形图像岗,我说实习投过这个岗位不合适,不会opengl和shador,然后hr就说秋招更看重基础。我当时
Java学习的正确打开方式
在博主认为,对于入门级学习java的最佳学习方法莫过于视频+博客+书籍+总结,前三者博主将淋漓尽致地挥毫于这篇博客文章中,至于总结在于个人,实际上越到后面你会发现学习的最好方式就是阅读参考官方文档其次就是国内的书籍,博客次之,这又是一个层次了,这里暂时不提后面再谈。博主将为各位入门java保驾护航,各位只管冲鸭!!!上天是公平的,只要不辜负时间,时间自然不会辜负你。 何谓学习?博主所理解的学习,它
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过
大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了
大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...
linux系列之常用运维命令整理笔录
本博客记录工作中需要的linux运维命令,大学时候开始接触linux,会一些基本操作,可是都没有整理起来,加上是做开发,不做运维,有些命令忘记了,所以现在整理成博客,当然vi,文件操作等就不介绍了,慢慢积累一些其它拓展的命令,博客不定时更新 顺便拉下票,我在参加csdn博客之星竞选,欢迎投票支持,每个QQ或者微信每天都可以投5票,扫二维码即可,http://m234140.nofollow.ax.
比特币原理详解
一、什么是比特币 比特币是一种电子货币,是一种基于密码学的货币,在2008年11月1日由中本聪发表比特币白皮书,文中提出了一种去中心化的电子记账系统,我们平时的电子现金是银行来记账,因为银行的背后是国家信用。去中心化电子记账系统是参与者共同记账。比特币可以防止主权危机、信用风险。其好处不多做赘述,这一层面介绍的文章很多,本文主要从更深层的技术原理角度进行介绍。 二、问题引入 假设现有4个人...
Python 基础(一):入门必备知识
目录1 标识符2 关键字3 引号4 编码5 输入输出6 缩进7 多行8 注释9 数据类型10 运算符10.1 常用运算符10.2 运算符优先级 1 标识符 标识符是编程时使用的名字,用于给变量、函数、语句块等命名,Python 中标识符由字母、数字、下划线组成,不能以数字开头,区分大小写。 以下划线开头的标识符有特殊含义,单下划线开头的标识符,如:_xxx ,表示不能直接访问的类属性,需通过类提供
这30个CSS选择器,你必须熟记(上)
关注前端达人,与你共同进步CSS的魅力就是让我们前端工程师像设计师一样进行网页的设计,我们能轻而易举的改变颜色、布局、制作出漂亮的影音效果等等,我们只需要改几行代码,不需...
国产开源API网关项目进入Apache孵化器:APISIX
点击蓝色“程序猿DD”关注我回复“资源”获取独家整理的学习资料!近日,又有一个开源项目加入了这个Java开源界大名鼎鼎的Apache基金会,开始进行孵化器。项目名称:AP...
程序员接私活怎样防止做完了不给钱?
首先跟大家说明一点,我们做 IT 类的外包开发,是非标品开发,所以很有可能在开发过程中会有这样那样的需求修改,而这种需求修改很容易造成扯皮,进而影响到费用支付,甚至出现做完了项目收不到钱的情况。 那么,怎么保证自己的薪酬安全呢? 我们在开工前,一定要做好一些证据方面的准备(也就是“讨薪”的理论依据),这其中最重要的就是需求文档和验收标准。一定要让需求方提供这两个文档资料作为开发的基础。之后开发
网页实现一个简单的音乐播放器(大佬别看。(⊙﹏⊙))
今天闲着无事,就想写点东西。然后听了下歌,就打算写个播放器。 于是乎用h5 audio的加上js简单的播放器完工了。 欢迎 改进 留言。 演示地点跳到演示地点 html代码如下`&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;music&lt;/title&gt; &lt;meta charset="utf-8"&gt
Python十大装B语法
Python 是一种代表简单思想的语言,其语法相对简单,很容易上手。不过,如果就此小视 Python 语法的精妙和深邃,那就大错特错了。本文精心筛选了最能展现 Python 语法之精妙的十个知识点,并附上详细的实例代码。如能在实战中融会贯通、灵活使用,必将使代码更为精炼、高效,同时也会极大提升代码B格,使之看上去更老练,读起来更优雅。 1. for - else 什么?不是 if 和 else 才
数据库优化 - SQL优化
前面一篇文章从实例的角度进行数据库优化,通过配置一些参数让数据库性能达到最优。但是一些“不好”的SQL也会导致数据库查询变慢,影响业务流程。本文从SQL角度进行数据库优化,提升SQL运行效率。 判断问题SQL 判断SQL是否有问题时可以通过两个表象进行判断: 系统级别表象 CPU消耗严重 IO等待严重 页面响应时间过长
2019年11月中国大陆编程语言排行榜
2019年11月2日,我统计了某招聘网站,获得有效程序员招聘数据9万条。针对招聘信息,提取编程语言关键字,并统计如下: 编程语言比例 rank pl_ percentage 1 java 33.62% 2 c/c++ 16.42% 3 c_sharp 12.82% 4 javascript 12.31% 5 python 7.93% 6 go 7.25% 7
通俗易懂地给女朋友讲:线程池的内部原理
餐厅的约会 餐盘在灯光的照耀下格外晶莹洁白,女朋友拿起红酒杯轻轻地抿了一小口,对我说:“经常听你说线程池,到底线程池到底是个什么原理?”我楞了一下,心里想女朋友今天是怎么了,怎么突然问出这么专业的问题,但做为一个专业人士在女朋友面前也不能露怯啊,想了一下便说:“我先给你讲讲我前同事老王的故事吧!” 大龄程序员老王 老王是一个已经北漂十多年的程序员,岁数大了,加班加不动了,升迁也无望,于是拿着手里
经典算法(5)杨辉三角
杨辉三角 是经典算法,这篇博客对它的算法思想进行了讲解,并有完整的代码实现。
编写Spring MVC控制器的14个技巧
本期目录 1.使用@Controller构造型 2.实现控制器接口 3.扩展AbstractController类 4.为处理程序方法指定URL映射 5.为处理程序方法指定HTTP请求方法 6.将请求参数映射到处理程序方法 7.返回模型和视图 8.将对象放入模型 9.处理程序方法中的重定向 10.处理表格提交和表格验证 11.处理文件上传 12.在控制器中自动装配业务类 ...
腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹?
昨天,有网友私信我,说去阿里面试,彻底的被打击到了。问了为什么网上大量使用ThreadLocal的源码都会加上private static?他被难住了,因为他从来都没有考虑过这个问题。无独有偶,今天笔者又发现有网友吐槽了一道腾讯的面试题,我们一起来看看。 腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹? 在互联网职场论坛,一名程序员发帖求助到。二面腾讯,其中一个算法题:64匹
面试官:你连RESTful都不知道我怎么敢要你?
面试官:了解RESTful吗? 我:听说过。 面试官:那什么是RESTful? 我:就是用起来很规范,挺好的 面试官:是RESTful挺好的,还是自我感觉挺好的 我:都挺好的。 面试官:… 把门关上。 我:… 要干嘛?先关上再说。 面试官:我说出去把门关上。 我:what ?,夺门而去 文章目录01 前言02 RESTful的来源03 RESTful6大原则1. C-S架构2. 无状态3.统一的接
求小姐姐抠图竟遭白眼?痛定思痛,我决定用 Python 自力更生!
点击蓝色“Python空间”关注我丫加个“星标”,每天一起快乐的学习大家好,我是 Rocky0429,一个刚恰完午饭,正在用刷网页浪费生命的蒟蒻...一堆堆无聊八卦信息的网页内容慢慢使我的双眼模糊,一个哈欠打出了三斤老泪,就在此时我看到了一张图片:是谁!是谁把我女朋友的照片放出来的!awsl!太好看了叭...等等,那个背景上的一堆鬼画符是什么鬼?!真是看不下去!叔叔婶婶能忍,隔壁老王的三姨妈的四表...
为啥国人偏爱Mybatis,而老外喜欢Hibernate/JPA呢?
关于SQL和ORM的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行了一番讨论,感触还是有一些,于是就有了今天这篇文。 声明:本文不会下关于Mybatis和JPA两个持久层框架哪个更好这样的结论。只是摆事实,讲道理,所以,请各位看官勿喷。 一、事件起因 关于Mybatis和JPA孰优孰劣的问题,争论已经很多年了。一直也没有结论,毕竟每个人的喜好和习惯是大不相同的。我也看
SQL-小白最佳入门sql查询一
不要偷偷的查询我的个人资料,即使你再喜欢我,也不要这样,真的不好;
项目中的if else太多了,该怎么重构?
介绍 最近跟着公司的大佬开发了一款IM系统,类似QQ和微信哈,就是聊天软件。我们有一部分业务逻辑是这样的 if (msgType = "文本") { // dosomething } else if(msgType = "图片") { // doshomething } else if(msgType = "视频") { // doshomething } else { // doshom...
致 Python 初学者
欢迎来到“Python进阶”专栏!来到这里的每一位同学,应该大致上学习了很多 Python 的基础知识,正在努力成长的过程中。在此期间,一定遇到了很多的困惑,对未来的学习方向感到迷茫。我非常理解你们所面临的处境。我从2007年开始接触 python 这门编程语言,从2009年开始单一使用 python 应对所有的开发工作,直至今天。回顾自己的学习过程,也曾经遇到过无数的困难,也曾经迷茫过、困惑过。开办这个专栏,正是为了帮助像我当年一样困惑的 Python 初学者走出困境、快速成长。希望我的经验能真正帮到你
“狗屁不通文章生成器”登顶GitHub热榜,分分钟写出万字形式主义大作
一、垃圾文字生成器介绍 最近在浏览GitHub的时候,发现了这样一个骨骼清奇的雷人项目,而且热度还特别高。 项目中文名:狗屁不通文章生成器 项目英文名:BullshitGenerator 根据作者的介绍,他是偶尔需要一些中文文字用于GUI开发时测试文本渲染,因此开发了这个废话生成器。但由于生成的废话实在是太过富于哲理,所以最近已经被小伙伴们给玩坏了。 他的文风可能是这样的: 你发现,...
程序员:我终于知道post和get的区别
是一个老生常谈的话题,然而随着不断的学习,对于以前的认识有很多误区,所以还是需要不断地总结的,学而时习之,不亦说乎
《程序人生》系列-这个程序员只用了20行代码就拿了冠军
你知道的越多,你不知道的越多 点赞再看,养成习惯GitHub上已经开源https://github.com/JavaFamily,有一线大厂面试点脑图,欢迎Star和完善 前言 这一期不算《吊打面试官》系列的,所有没前言我直接开始。 絮叨 本来应该是没有这期的,看过我上期的小伙伴应该是知道的嘛,双十一比较忙嘛,要值班又要去帮忙拍摄年会的视频素材,还得搞个程序员一天的Vlog,还要写BU...
相关热词 c# clr dll c# 如何orm c# 固定大小的字符数组 c#框架设计 c# 删除数据库 c# 中文文字 图片转 c# 成员属性 接口 c#如何将程序封装 16进制负数转换 c# c#练手项目
立即提问

相似问题

2
请问:用Java代码中实现在一个类编写两种方法,下面的代码接下来怎么办呢?谢谢!
1
请问:用java代码mysql如何加载到memcached中?谢谢!!
1
请问:java中,运用属性文件的方法怎么把mysql加载到memcached中?谢谢!
5
请问:用java代码把不同的excel形式加载到MySQL数据库中(循环判断空就停止)?谢谢!
11
请问:以下代码什么意思?谢谢!!
5
请问:用java代码把excel导入数据库时,出现问题
2
请问:用java代码怎样读取MySQL数据库生成JSP文件?谢谢!
6
请问:java代码通过io流怎么读取MySQL数据库生成jsp文件?谢谢!
2
请问有没有用java代码实现另存为的源代码?谢谢!
1
请问各位有没有memcached java比较全的代码,谢谢!
0
请问:JAVA代码如何实现memcache连接JNDI?谢谢!!
2
急求:java代码如何实现MySQL数据库的读写(数据库里面有很多表)?谢谢??
5
java代码判断本机是否连接上外网
1
十万火急::Java判断服务器的文件是否存在如果不存在就上传、如果存在,在上传的时候删除文件
3
请问:有谁有用java ee做的教学推荐系统,最好是全的代码,谢谢!
2
携程机票预订后台java开发编程具体代码?麻烦会的给发一下!谢谢!!!
4
求java清屏代码,谢各位大神!!!
1
java代码混淆工具求推荐
2
java用代码启动openoffice服务时报错。。。。求大牛解决啊
4
求:Java工厂模式的应用!!!!