【问题标题】:Springboot war in tomcat not workingtomcat中的Spring Boot战争不起作用
【发布时间】:2017-04-15 09:11:32
【问题描述】:

我正在尝试在Tomcat中部署一个用springboot生成的war,我之前已经成功了,但是这次不知道出了什么问题。

最重要的代码添加:

config/AppConfig

@Configuration
@EnableTransactionManagement
@Component
//@EnableWebMvc
@ComponentScan("com.singleuseapps")
public class AppConfig {

LaptopsApplication

@SpringBootApplication
@ComponentScan(basePackageClasses =      {AppConfig.class,LaptopsApplication.class})
public class LaptopsApplication extends SpringBootServletInitializer {


@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
    return builder.sources(LaptopsApplication.class);
}

public static void main(String[] args) {
    SpringApplication.run(LaptopsApplication.class, args);
}

build.gradle

buildscript {
ext {
    springBootVersion = '1.4.2.RELEASE'
}
repositories {
    mavenCentral()
}
dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'idea'
apply plugin: 'war'

springBoot{
   executable = true
}

jar {
    baseName = 'laptops'
}

war {
    baseName = 'laptops'
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile 'org.hibernate:hibernate-core:5.0.9.Final'
compile("com.h2database:h2")
testCompile('org.springframework.boot:spring-boot-starter-test')
compile 'javax.servlet:javax.servlet-api:3.1.0'
compile 'org.javassist:javassist:3.15.0-GA'
compile 'mysql:mysql-connector-java:5.1.31'
compile 'commons-dbcp:commons-dbcp:1.4'
compile('org.springframework.boot:spring-boot-starter-jdbc')
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
compileOnly "org.projectlombok:lombok:1.16.10"
compile "io.springfox:springfox-swagger2:2.6.0"
compile 'io.springfox:springfox-swagger-ui:2.6.0'
compile 'com.sun.mail:javax.mail'
compile( 'org.springframework.boot:spring-boot-starter-mail')
}

希望有人知道我失败的原因。

[编辑]

catalina.out 中的行

Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.singleuseapps.LaptopsApplication]; nested exception is java.io.FileNotFoundException: class path resource [com/singleuseapps/cart/TestMailController.class] cannot be opened because it does not exist

【问题讨论】:

  • 你应该给出确切的错误
  • 在 tomcat 中测试端点时得到 404
  • 你在部署阶段没有错误?
  • 检查 catalina.out 是否有一些异常堆栈跟踪。
  • 在哪里可以找到 catalina.out? -edit 找到了

标签: java spring tomcat spring-boot war


【解决方案1】:

你应该:

  • 从 AppConfig 中移除 @Component(它已经用 @Configuration 注解了)
  • 从LaptopsApplication中移除.configure方法,它已经被@SpringBootApplication注解并且自动成为一个配置类,你不需要再次添加它
  • 确保您的控制器类位于您的两个 @ComponentScan 注释指定的包中(您可能只需要主应用程序类中的那个)

【讨论】:

    猜你喜欢
    • 2019-10-27
    • 2015-10-28
    • 2019-03-21
    • 1970-01-01
    • 2018-11-03
    • 2022-11-10
    • 2019-09-30
    • 2020-02-26
    • 2021-01-26
    相关资源
    最近更新 更多