2016-11-30 58 views
0

我试图在Tomcat中部署一个使用springboot生成的战争,在这个战斗中我已经成功了,但是这次却弄不清楚什么是错误的。在Tomcat的Springboot战争不起作用

最重要的代码添加:

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') 
} 

希望有人得到我为什么失败。

[编辑]

Line在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 
+0

你应该给予确切的错误 – davidxxx

+0

我得到在tomcat中测试端点时使用的404是 – Stefan

+0

而您在部署阶段没有错误? – davidxxx

回答

0

您应该:从AppConfig中

  • 删除@Component(它已经与@Configuration注释)
  • 删除。从LaptopsApplication配置方法,它已经使用@SpringBootApplication进行了注释,并自动成为您不需要的配置类d添加它再次
  • 确保您的控制器类是由你的两个@ComponentScan注解指定的包(您可能只需要在你的主应用程序类中的一个)
+0

试过了,但它不能解决我的问题 – Stefan

相关问题