之前的技术栈一直是围绕.net 做的,现在.net 技术栈的使用越来越少,越来越窄。好多原来的同事都转Java开发了。
最近公司变动,自己需要重新找个坑,压力山大。好多要求Java技术栈的根本没机会进,自己的那点Java功底,之前做过混合开发的Java插件,Web项目10多年没碰了...
好在几个原来的同事都是所在公司的骨干,Java也用的很溜,嗯,向人家学习吧。。。
先把相关的家伙事准备好。
该安装的安装,该配置的配置。
开始架构第一个项目。点菜单File->New->Project。打开New Project窗口。左边选Spring,右边选择Spring MVC。
拉到下边选择Hibernate和SQL Support,数据库支持选择MySQL
点击下边Next,给项目一个名字,JavaStudy。设置项目存放目录。设置完成后点击下边的按钮Finish。然后开始自动下载所依赖的相关包。
很快下载完成,第一个项目基本轮廓就有了。
选中web目录下的index.jsp然后点击菜单Run->run 'index.jsp',开始第一次运行。。。
[2019-07-21 12:23:40,433] Artifact JavaStudy:war exploded: Artifact is being deployed, please wait... 21-Jul-2019 12:23:40.672 警告 [RMI TCP Connection(2)-127.0.0.1] org.apache.tomcat.util.descriptor.web.WebXml.setVersion Unknown version string [4.0]. Default version will be used. 21-Jul-2019 12:23:40.786 严重 [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file 21-Jul-2019 12:23:40.788 严重 [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal Context [/JavaStudy_war_exploded] startup failed due to previous errors [2019-07-21 12:23:40,804] Artifact JavaStudy:war exploded: Error during artifact deployment. See server log for details.
第一次运行果然会掉进坑里...。各种搜索,然后做了下边的操作。在web->WEB-INF目录下新建一个classes目录。然后建一个logging.properties文件。
logging.properties文件内容如下:
handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHandler ############################################################ # Handler specific properties. # Describes specific configuration info for Handlers. ############################################################ org.apache.juli.FileHandler.level = FINE org.apache.juli.FileHandler.directory = ../logs org.apache.juli.FileHandler.prefix = error-debug. java.util.logging.ConsoleHandler.level = FINE java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
这样运行后控制台就可以显示具体的错误。否则只显示出错,不显示具体内容,再次运行,
严重: Error configuring application listener of class [org.springframework.web.context.ContextLoaderListener] java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1360) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1182) at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:546) at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:527) at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:150) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4621) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5165) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:743) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:719) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714) at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1720) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [2019-07-21 12:28:31,020] Artifact JavaStudy:war exploded: Error during artifact deployment. See server log for details. 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.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:287) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:483) at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:432) 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.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:287) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) at com.sun.jmx.remote.security.MBeanServerAccessController.invoke(MBeanServerAccessController.java:468) at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468) at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76) at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309) at java.security.AccessController.doPrivileged(Native Method) at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1408) at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829) 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 sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357) at sun.rmi.transport.Transport$1.run(Transport.java:200) at sun.rmi.transport.Transport$1.run(Transport.java:197) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:196) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687) 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)
java.lang.ClassNotFoundException,这应该是没有找到这个包。新创建的项目按道理说不应该啊。选中项目,然后按F4,打开Project Structure窗口。
在Project Settings找到了Artifacts中找到了一些问题提示。项目输出结构貌似有问题。依赖包找不到
点击下边的Fix按钮,选择Add all missing 。。。
三个缺失的依赖库被自动添加了
点击OK,再次运行...,
浏览器打开了,这是要成功的节奏啊。期待hello world...
404是几个意思?
又掉坑里了...
用IDEA+Tomcat + 404做关键字,搜索后找到了类似的问题,
Run->Edit Configuration,打开Run/Debug Configurations,选中Tomcate Server下的index.jsp,右边选择Deployment选项卡,然后把Application context 下的内容改成“/”,点击按钮OK
再次运行。。。
终于出来了
出现java.io.FileNotFoundException: C:Program FilesApache Software FoundationTomcat 8.5in..logserror-debug.2019-07-25.log (拒绝访问。)错误的时候是因为权限不足,无法写入权限,用管理员身份运行Intellij IDEA即可。或者找到写log的配置项,把log位置配置到有权限的位置也可以。