将SpringBoot部署在外部tomcat中
一,前言
在文章SpringBoot之简单入门中提到了,SpringBoot是内置一个tomcat容器的,但是如果要将SpringBoot部署在一个外部的tomcat,要怎么办呢?这就是本篇文章的目的了。
在文章SpringBoot之整合Mybatis(增,改,删)中我们实现了mybatis的增,改,删功能,那么,我们就将文章中的示例工程部署到一个外部的tomcat。
二,继承SpringBootServletInitializer并重写configure方法
代码:
package com.zcz; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; @SpringBootApplication public class LearnSpringBootWithMybatis2Application extends SpringBootServletInitializer{ public static void main(String[] args) { SpringApplication.run(LearnSpringBootWithMybatis2Application.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { // TODO Auto-generated method stub // return super.configure(builder); return builder.sources(this.getClass()); } }
三,修改pom.xml禁用springboot内置的tomcat,并将打包方式改为war
添加配置:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <!-- provided 表明该包只在编译和测试的时候使用,去除默认的tomcat --> <scope>provided</scope> </dependency>
将jar改为war
<packaging>war</packaging>
修改完成后,整体的pom.xml文件为:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.zcz</groupId> <artifactId>learnSpringBootWithMybatis2</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>learnSpringBootWithMybatis2</name> <description>learnSpringBootWithMybatis</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.5.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.2</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <!-- provided 表明该包只在编译和测试的时候使用,去除默认的tomcat --> <scope>provided</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
四,打war包
在工程上右键->Run As ->Maven clean。
接着右键->Run As -> Maven install。
然后就可以在target中看到打好的war包了
五,启动tomcat
为了方便运行,将tomcat的webapps目录清空,将我们打好的war包,拷贝到webapps目录中,并将名称更改为ROOT.war。
进入tomcat的bin目录,双击startup.bat,启动tomcat。
糟了,出现异常了:java.lang.NoClassDefFoundError: javax/el/ELManager
完整的错误信息,如下:
十月 09, 2018 3:27:53 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Server version: Apache Tomcat/7.0.85 十月 09, 2018 3:27:53 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Server built: Feb 7 2018 18:52:33 UTC 十月 09, 2018 3:27:53 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Server number: 7.0.85.0 十月 09, 2018 3:27:53 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: OS Name: Windows 8.1 十月 09, 2018 3:27:53 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: OS Version: 6.3 十月 09, 2018 3:27:53 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Architecture: amd64 十月 09, 2018 3:27:53 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Java Home: G:\tools\JDK8_64\jre 十月 09, 2018 3:27:53 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: JVM Version: 1.8.0_40-b25 十月 09, 2018 3:27:53 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: JVM Vendor: Oracle Corporation 十月 09, 2018 3:27:53 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: CATALINA_BASE: G:\myservices\tomcat-7.0.85-springbootmybatis 十月 09, 2018 3:27:53 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: CATALINA_HOME: G:\myservices\tomcat-7.0.85-springbootmybatis 十月 09, 2018 3:27:53 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Djava.util.logging.config.file=G:\myservices\tomcat-7.0.85-springbootmybatis\conf\logging.properties 十月 09, 2018 3:27:53 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager 十月 09, 2018 3:27:53 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Xms2048m 十月 09, 2018 3:27:53 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Xmx2048m 十月 09, 2018 3:27:53 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Xss1024K 十月 09, 2018 3:27:53 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -XX:MetaspaceSize=20m 十月 09, 2018 3:27:53 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -XX:MaxMetaspaceSize=512m 十月 09, 2018 3:27:53 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Djdk.tls.ephemeralDHKeySize=2048 十月 09, 2018 3:27:53 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Dignore.endorsed.dirs= 十月 09, 2018 3:27:53 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Dcatalina.base=G:\myservices\tomcat-7.0.85-springbootmybatis 十月 09, 2018 3:27:53 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Dcatalina.home=G:\myservices\tomcat-7.0.85-springbootmybatis 十月 09, 2018 3:27:53 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Djava.io.tmpdir=G:\myservices\tomcat-7.0.85-springbootmybatis\temp 十月 09, 2018 3:27:53 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent 信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: G:\tools\JDK8_64\jre\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Python\Python365\Scripts\;C:\Python\Python365\;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Prog ram Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Java\jdk-10\bin;C:\Program Files\Java\jdk-10;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;. 十月 09, 2018 3:27:53 下午 org.apache.coyote.AbstractProtocol init 信息: Initializing ProtocolHandler ["http-bio-80"] 十月 09, 2018 3:27:53 下午 org.apache.coyote.AbstractProtocol init 信息: Initializing ProtocolHandler ["ajp-bio-8009"] 十月 09, 2018 3:27:53 下午 org.apache.catalina.startup.Catalina load 信息: Initialization processed in 1256 ms 十月 09, 2018 3:27:53 下午 org.apache.catalina.core.StandardService startInternal 信息: Starting service Catalina 十月 09, 2018 3:27:53 下午 org.apache.catalina.core.StandardEngine startInternal 信息: Starting Servlet Engine: Apache Tomcat/7.0.85 十月 09, 2018 3:27:53 下午 org.apache.catalina.startup.HostConfig deployWAR 信息: Deploying web application archive G:\myservices\tomcat-7.0.85-springbootmybatis\webapps\ROOT.war 十月 09, 2018 3:27:57 下午 org.apache.catalina.startup.TldConfig execute 信息: 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. . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.0.5.RELEASE) 2018-10-09 15:28:00.126 INFO 3216 --- [ost-startStop-1] z.LearnSpringBootWithMybatis2Application : Starting LearnSpringBootWithMybatis2Application on idea-PC with PID 3216 (G:\myservices\tomcat-7.0.85-springbootmybatis\webapps\ROOT\WEB-INF\classes started by zongwu in G:\myservices\tomcat-7.0.85-springbootmybatis\bin) 2018-10-09 15:28:00.131 INFO 3216 --- [ost-startStop-1] z.LearnSpringBootWithMybatis2Application : The following profiles are active: online 2018-10-09 15:28:00.190 INFO 3216 --- [ost-startStop-1] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@1b9aacaf: startup date [Tue Oct 09 15:28:00 CST 2018]; root of context hierarchy 2018-10-09 15:28:02.598 INFO 3216 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2411 ms 2018-10-09 15:28:03.640 INFO 3216 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/] 2018-10-09 15:28:03.642 INFO 3216 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*] 2018-10-09 15:28:03.643 INFO 3216 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'errorPageFilter' to: [/*] 2018-10-09 15:28:03.643 INFO 3216 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*] 2018-10-09 15:28:03.644 INFO 3216 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*] 2018-10-09 15:28:03.644 INFO 3216 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*] 2018-10-09 15:28:04.548 WARN 3216 --- [ost-startStop-1] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultValidator' defined in class path resource [org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.Be anInstantiationException: Failed to instantiate [org.springframework.validation.beanvalidation.LocalValidatorFactoryBean]: Factory method 'defaultValidator' threw exception; nested exception is java.lang.NoClassDefFoundError: javax/el/ELManager 2018-10-09 15:28:04.567 INFO 3216 --- [ost-startStop-1] ConditionEvaluationReportLoggingListener : Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2018-10-09 15:28:04.580 ERROR 3216 --- [ost-startStop-1] o.s.boot.SpringApplication : Application run failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultValidator' defined in class path resource [org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.validation.beanvalidation.LocalValidatorFactoryBean]: Factory method 'defaultValidator' threw exception; nested e xception is java.lang.NoClassDefFoundError: javax/el/ELManager at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:590) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1247) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$141/1748549073.getObject(Unknown Source) ~[na:na] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:780) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:333) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE] at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:157) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE] at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:137) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE] at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:91) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE] at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:172) [spring-web-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5630) [catalina.jar:7.0.85] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145) [catalina.jar:7.0.85] at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1015) [catalina.jar:7.0.85] at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:991) [catalina.jar:7.0.85] at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652) [catalina.jar:7.0.85] at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1127) [catalina.jar:7.0.85] at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:2020) [catalina.jar:7.0.85] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_40] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_40] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_40] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_40] at java.lang.Thread.run(Thread.java:745) [na:1.8.0_40] Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.validation.beanvalidation.LocalValidatorFactoryBean]: Factory method 'defaultValidator' threw exception; nested exception is java.lang.NoClassDefFoundError: javax/el/ELManager at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:582) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] ... 32 common frames omitted Caused by: java.lang.NoClassDefFoundError: javax/el/ELManager at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.buildExpressionFactory(ResourceBundleMessageInterpolator.java:88) ~[hibernate-validator-6.0.12.Final.jar:6.0.12.Final] at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.<init>(ResourceBundleMessageInterpolator.java:47) ~[hibernate-validator-6.0.12.Final.jar:6.0.12.Final] at org.hibernate.validator.internal.engine.ConfigurationImpl.getDefaultMessageInterpolator(ConfigurationImpl.java:474) ~[hibernate-validator-6.0.12.Final.jar:6.0.12.Final] at org.springframework.boot.validation.MessageInterpolatorFactory.getObject(MessageInterpolatorFactory.java:54) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE] at org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration.defaultValidator(ValidationAutoConfiguration.java:57) ~[spring-boot-autoconfigure-2.0.5.RELEASE.jar:2.0.5.RELEASE] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_40] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_40] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_40] at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_40] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] ... 33 common frames omitted 十月 09, 2018 3:28:04 下午 org.apache.catalina.core.ContainerBase addChildInternal 严重: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1015) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:991) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652) at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1127) at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:2020) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultValidator' defined in class path resource [org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.validation.beanvalidation.LocalValidatorFactoryBean]: Factory method 'defaultValidator' threw exceptio n; nested exception is java.lang.NoClassDefFoundError: javax/el/ELManager at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:590) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1247) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$141/1748549073.getObject(Unknown Source) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:780) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) at org.springframework.boot.SpringApplication.run(SpringApplication.java:333) at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:157) at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:137) at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:91) at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:172) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5630) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145) ... 10 more Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.validation.beanvalidation.LocalValidatorFactoryBean]: Factory method 'defaultValidator' threw exception; nested exception is java.lang.NoClassDefFoundError: javax/el/ELManager at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:582) ... 32 more Caused by: java.lang.NoClassDefFoundError: javax/el/ELManager at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.buildExpressionFactory(ResourceBundleMessageInterpolator.java:88) at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.<init>(ResourceBundleMessageInterpolator.java:47) at org.hibernate.validator.internal.engine.ConfigurationImpl.getDefaultMessageInterpolator(ConfigurationImpl.java:474) at org.springframework.boot.validation.MessageInterpolatorFactory.getObject(MessageInterpolatorFactory.java:54) at org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration.defaultValidator(ValidationAutoConfiguration.java:57) 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:497) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ... 33 more 十月 09, 2018 3:28:04 下午 org.apache.catalina.startup.HostConfig deployWAR 严重: Error deploying web application archive G:\myservices\tomcat-7.0.85-springbootmybatis\webapps\ROOT.war java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]] at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1019) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:991) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652) at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1127) at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:2020) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) 十月 09, 2018 3:28:04 下午 org.apache.catalina.startup.HostConfig deployWAR 信息: Deployment of web application archive G:\myservices\tomcat-7.0.85-springbootmybatis\webapps\ROOT.war has finished in 10,975 ms 十月 09, 2018 3:28:04 下午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["http-bio-80"] 十月 09, 2018 3:28:04 下午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["ajp-bio-8009"] 十月 09, 2018 3:28:04 下午 org.apache.catalina.startup.Catalina start 信息: Server startup in 11111 ms
这个问题是因为el的jar包引起的。
如果你是使用的idea,那么请参考文章:https://blog.csdn.net/qq_14853889/article/details/80026885
如果使用的是eclipse,就先查看eclipse中使用的jar包的位置:
找到这个jar包,拷贝到tomcat的lib中。问题即可解决,启动成功控制台打印信息:
十月 09, 2018 3:37:57 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Server version: Apache Tomcat/7.0.85 十月 09, 2018 3:37:57 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Server built: Feb 7 2018 18:52:33 UTC 十月 09, 2018 3:37:57 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Server number: 7.0.85.0 十月 09, 2018 3:37:57 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: OS Name: Windows 8.1 十月 09, 2018 3:37:57 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: OS Version: 6.3 十月 09, 2018 3:37:57 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Architecture: amd64 十月 09, 2018 3:37:57 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Java Home: G:\tools\JDK8_64\jre 十月 09, 2018 3:37:57 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: JVM Version: 1.8.0_40-b25 十月 09, 2018 3:37:57 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: JVM Vendor: Oracle Corporation 十月 09, 2018 3:37:57 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: CATALINA_BASE: G:\myservices\tomcat-7.0.85-springbootmybatis 十月 09, 2018 3:37:57 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: CATALINA_HOME: G:\myservices\tomcat-7.0.85-springbootmybatis 十月 09, 2018 3:37:57 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Djava.util.logging.config.file=G:\myservices\tomcat-7.0.85-springbootmybatis\conf\logging.properties 十月 09, 2018 3:37:57 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager 十月 09, 2018 3:37:57 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Xms2048m 十月 09, 2018 3:37:57 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Xmx2048m 十月 09, 2018 3:37:57 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Xss1024K 十月 09, 2018 3:37:57 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -XX:MetaspaceSize=20m 十月 09, 2018 3:37:57 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -XX:MaxMetaspaceSize=512m 十月 09, 2018 3:37:57 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Djdk.tls.ephemeralDHKeySize=2048 十月 09, 2018 3:37:57 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Dignore.endorsed.dirs= 十月 09, 2018 3:37:57 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Dcatalina.base=G:\myservices\tomcat-7.0.85-springbootmybatis 十月 09, 2018 3:37:57 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Dcatalina.home=G:\myservices\tomcat-7.0.85-springbootmybatis 十月 09, 2018 3:37:57 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Djava.io.tmpdir=G:\myservices\tomcat-7.0.85-springbootmybatis\temp 十月 09, 2018 3:37:57 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent 信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: G:\tools\JDK8_64\jre\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Python\Python365\Scripts\;C:\Python\Python365\;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Prog ram Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Java\jdk-10\bin;C:\Program Files\Java\jdk-10;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;. 十月 09, 2018 3:37:57 下午 org.apache.coyote.AbstractProtocol init 信息: Initializing ProtocolHandler ["http-bio-80"] 十月 09, 2018 3:37:57 下午 org.apache.coyote.AbstractProtocol init 信息: Initializing ProtocolHandler ["ajp-bio-8009"] 十月 09, 2018 3:37:57 下午 org.apache.catalina.startup.Catalina load 信息: Initialization processed in 1020 ms 十月 09, 2018 3:37:57 下午 org.apache.catalina.core.StandardService startInternal 信息: Starting service Catalina 十月 09, 2018 3:37:57 下午 org.apache.catalina.core.StandardEngine startInternal 信息: Starting Servlet Engine: Apache Tomcat/7.0.85 十月 09, 2018 3:37:57 下午 org.apache.catalina.startup.HostConfig deployWAR 信息: Deploying web application archive G:\myservices\tomcat-7.0.85-springbootmybatis\webapps\ROOT.war 十月 09, 2018 3:38:00 下午 org.apache.catalina.startup.TldConfig execute 信息: 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. . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.0.5.RELEASE) 2018-10-09 15:38:02.562 INFO 8456 --- [ost-startStop-1] z.LearnSpringBootWithMybatis2Application : Starting LearnSpringBootWithMybatis2Application on idea-PC with PID 8456 (G:\myservices\tomcat-7.0.85-springbootmybatis\webapps\ROOT\WEB-INF\classes started by zongwu in G:\myservices\tomcat-7.0.85-springbootmybatis\bin) 2018-10-09 15:38:02.567 INFO 8456 --- [ost-startStop-1] z.LearnSpringBootWithMybatis2Application : The following profiles are active: online 2018-10-09 15:38:02.719 INFO 8456 --- [ost-startStop-1] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@4eb8b69d: startup date [Tue Oct 09 15:38:02 CST 2018]; root of context hierarchy 2018-10-09 15:38:05.239 INFO 8456 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2523 ms 2018-10-09 15:38:06.063 INFO 8456 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/] 2018-10-09 15:38:06.067 INFO 8456 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*] 2018-10-09 15:38:06.068 INFO 8456 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'errorPageFilter' to: [/*] 2018-10-09 15:38:06.069 INFO 8456 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*] 2018-10-09 15:38:06.072 INFO 8456 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*] 2018-10-09 15:38:06.073 INFO 8456 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*] 2018-10-09 15:38:07.035 INFO 8456 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2018-10-09 15:38:07.436 INFO 8456 --- [ost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@4eb8b69d: startup date [Tue Oct 09 15:38:02 CST 2018]; root of context hierarchy 2018-10-09 15:38:07.600 INFO 8456 --- [ost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/user/getUser]}" onto public java.util.List<com.zcz.entity.User> com.zcz.controller.UserController.getUsers() 2018-10-09 15:38:07.604 INFO 8456 --- [ost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/user/addUser]}" onto public void com.zcz.controller.UserController.addUser(javax.servlet.http.HttpServletRequest) 2018-10-09 15:38:07.605 INFO 8456 --- [ost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/user/updateUser]}" onto public void com.zcz.controller.UserController.updateUser(javax.servlet.http.HttpServletRequest) 2018-10-09 15:38:07.606 INFO 8456 --- [ost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/user/deleteUser]}" onto public void com.zcz.controller.UserController.deleteUser(javax.servlet.http.HttpServletRequest) 2018-10-09 15:38:07.607 INFO 8456 --- [ost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/user/getUserOne]}" onto public com.zcz.entity.User com.zcz.controller.UserController.getUserOne(javax.servlet.http.HttpServletRequest) 2018-10-09 15:38:07.613 INFO 8456 --- [ost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest) 2018-10-09 15:38:07.620 INFO 8456 --- [ost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) 2018-10-09 15:38:07.710 INFO 8456 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2018-10-09 15:38:07.712 INFO 8456 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2018-10-09 15:38:08.280 INFO 8456 --- [ost-startStop-1] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2018-10-09 15:38:08.303 INFO 8456 --- [ost-startStop-1] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'dataSource' has been autodetected for JMX exposure 2018-10-09 15:38:08.315 INFO 8456 --- [ost-startStop-1] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource] 2018-10-09 15:38:08.342 INFO 8456 --- [ost-startStop-1] z.LearnSpringBootWithMybatis2Application : Started LearnSpringBootWithMybatis2Application in 7.66 seconds (JVM running for 12.232) 十月 09, 2018 3:38:08 下午 org.apache.catalina.startup.HostConfig deployWAR 信息: Deployment of web application archive G:\myservices\tomcat-7.0.85-springbootmybatis\webapps\ROOT.war has finished in 10,902 ms 十月 09, 2018 3:38:08 下午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["http-bio-80"] 十月 09, 2018 3:38:08 下午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["ajp-bio-8009"] 十月 09, 2018 3:38:08 下午 org.apache.catalina.startup.Catalina start 信息: Server startup in 11032 ms
接下来测试一下功能是否可以实现,就测试一个新增功能吧。
浏览器访问:http://localhost/user/addUser?name=chegnzilalala
查看数据库:
说明数据成功插入。
你可能会奇怪,为什么没有加8080端口,那是因为我在application.yml文件中配置了80端口,http协议默认是80端口,所以在浏览器中访问的时候就可以不加端口
server:
port: 80
源代码,我已经更新到了github : https://github.com/ZCC1/learnSpringBootWithMybatis2.git,有需要的小伙伴可以去clone
原创不易,转载请声明出处:https://www.cnblogs.com/zhangchengzi/p/9760712.html
才疏学浅,如有错误,欢迎大家留言评论。
如果大家觉得我的文章写的不错,“关注我”或者“推荐一下”吧,我会继续努力写出更好的文章。
觉得哪里写的不好的,可以留言或者加我微信告诉我。
另外我建立一个技术讨论群,欢迎大家来学习探讨,微信:fcg606808。