spring boot war部署及遇到的异常问题(不带web.xml)

SpringBoot 打包成war包部署到tomcat(不带 web.xml文件 servlet3.0及之后可以不用配置)

在用idea 搭建 spring boot 并打包发布到外部tomcat部署,原本以为很简单的事情,没想到还是遇到了一些异常情况,

找了好多资料都没有解决问题,今天无意中找到一个方案搞定了,随写下用以记录

途中遇到的异常:

 1.因为最简单的demo所以没有用到相关的事物,因此需要在启动类里移除TransactionAutoConfiguration 类

   参考链接:点击打开链接

   这种错误一般是因为加载了组件,但是没有正确配置,这也就可以通过 exclude 移除掉

  如果出现 DataSourceAutoConfiguration 相关的错误 也可以直接移除

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration$EnableTransactionManagementConfiguration$CglibAutoProxyConfiguration]; nested exception is java.lang.IllegalArgumentException: class org.springframework.transaction.annotation.TransactionManagementConfigurationSelector is not assignable to interface org.springframework.context.annotation.ImportSelector
	at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:616) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:296) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:241) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
07-Mar-2018 11:29:39.675 严重 [RMI TCP Connection(4)-127.0.0.1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start: 
	at org.springframework.context.annotation.ConfigurationClassParser.processMemberClasses(ConfigurationClassParser.java:355) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
 org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:261) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:241) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]

附带. pom.xml 配置文件

   
      org.springframework.boot
      <artifactId>spring-boot-starter-webartifactId>
   
   
      org.springframework.boot
      <artifactId>spring-boot-starter-tomcatartifactId>
      provided
   
   
      org.springframework.boot
      <artifactId>spring-boot-starter-testartifactId>
      test
   



   
      
      
         org.apache.maven.plugins
         maven-war-plugin
         
            false
         
      
   
. application 启动类
 
  
@SpringBootApplication
@EnableAutoConfiguration(exclude = {TransactionAutoConfiguration.class, DataSourceAutoConfiguration.class})
public class ChatApplication extends SpringBootServletInitializer {

   @Override
   protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
      return application.sources(ChatApplication.class);
   }
   public static void main(String[] args) {
      SpringApplication.run(ChatApplication.class, args);
   }

}

你可能感兴趣的:(spring)