tomcat中的Springboot战无法正常工作

时间:2016-11-30 21:34:00

标签: java spring tomcat spring-boot war

我正在尝试在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

1 个答案:

答案 0 :(得分:0)

你应该:

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