使用IDEA在tomcat中部署maven多模块时出现的一个莫名的bug
首先在server中打印下: 可以看见 context [] startup failed due to previous error, see server log for details.
[2018-10-19 10:55:28,273] Artifact springmvc-test:war exploded: Artifact is being deployed, please wait...
Oct 19, 2018 10:55:29 AM org.apache.catalina.startup.TldConfig execute
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were
scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Oct 19, 2018 10:55:30 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file
Oct 19, 2018 10:55:30 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [] startup failed due to previous errors
[2018-10-19 10:55:30,410] Artifact springmvc-test:war exploded: Error during artifact deployment. See server log for details.
Oct 19, 2018 10:55:38 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/apache-tomcat-7.0.90/webapps/manager
Oct 19, 2018 10:55:38 AM org.apache.catalina.startup.TldConfig execute
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were
scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Oct 19, 2018 10:55:38 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /opt/apache-tomcat-7.0.90/webapps/manager has finished in 222 ms
于是我们打开tomcat日志位置并查看: 显示framework-base中的ConfigItem NotFound.
zwj@ubuntu:~/.IntelliJIdea2018.1/system/tomcat/Unnamed_learn/logs$ ls
catalina.2018-10-18.log localhost_access_log.2018-10-17.txt catalina.2018-10-19.log localhost_access_log.2018-10-18.txt
host-manager.2018-10-18.log localhost_access_log.2018-10-19.txt host-manager.2018-10-19.log manager.2018-10-18.log
localhost.2018-10-18.log manager.2018-10-19.log localhost.2018-10-19.log
cat localhost。2018-10-19.log
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.zwj.framework.base.config.ConfigItem] for bean with name
'com.zwj.framework.base.config.ConfigItem#0' defined in class path resource [spring/applicationContext.xml]; nested exception is
java.lang.ClassNotFoundException: com.zwj.framework.base.config.ConfigItem
果然在war包下的lib中并没有framework-base,springwork-mybatis等子模块的jar包:
显然使用idea点击运行tomcat时,在编译打包过程中我们的子模块给遗漏了?带着问题继续查看IDEA的日志。。。
zwj@ubuntu:~$ cd .IntelliJIdea2018.1/system/log/
zwj@ubuntu:~/.IntelliJIdea2018.1/system/log$ ls
build-log idea.log.2 idea.log.5
idea.log idea.log.3 threadDumps-freeze-20181016-152806-IU-181.5540.7-20sec
idea.log.1 idea.log.4
zwj@ubuntu:~/.IntelliJIdea2018.1/system/log$ tail -f idea.log
com.intellij.execution.ExecutionException: Cannot load /home/zwj/learn/learn/springmvc-test/target/artifacts/springmvc_test_war_exploded
/META-INF/context.xml: /home/zwj/learn/learn/springmvc-test/target/artifacts/springmvc_test_war_exploded/META-INF/context.xml (No such file or
directory)
at org.jetbrains.idea.tomcat.TomcatUtil.loadXMLFile(TomcatUtil.java:208)
at org.jetbrains.idea.tomcat.TomcatUtil.findContextInContextXml(TomcatUtil.java:107)
at org.jetbrains.idea.tomcat.TomcatUtil.findContextElement(TomcatUtil.java:381)
at org.jetbrains.idea.tomcat.admin.TomcatAdminLocalServerImpl.addApplicationContext(TomcatAdminLocalServerImpl.java:191)
百度了半天发现,这个context文件没有加载并不是错误的根本,而是没有导入子模块的jar包时产生的子错误。
庆幸的是最终还是找到了错误,我们看到下图中artifacts的lib中没有子模块的jar包,需要先点击lib,然后在available elements中点开相应模块,然后再
pack into进去。
最后点击运行就行了。。。。。。。
坑。。。。。