我正在尝试将Spring Boot war文件部署到jboss 7.我没有在任何地方使用MongoDB,但不知怎的,我收到了MongoClientOptions的NoClassDefFoundError错误:
16:15:04,876 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC00001: Failed to start service jboss.deployment.unit."myapp-0.1.0.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."myapp-0.1.0.war".INSTALL: Failed to process phase INSTALL of deployment "myapp-0.1.0.war"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:121)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)
at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [:1.8.0_112]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [:1.8.0_112]
at java.lang.Thread.run(Thread.java:745) [:1.8.0_112]
Caused by: java.lang.RuntimeException: Error getting reflective information for class org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration
at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:70)
at org.jboss.as.ee.component.EEModuleClassDescription$DefaultConfigurator.configure(EEModuleClassDescription.java:144)
at org.jboss.as.ee.component.EEClassConfigurationProcessor.deploy(EEClassConfigurationProcessor.java:100)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:115)
... 5 more
Caused by: java.lang.NoClassDefFoundError: Lcom/mongodb/MongoClientOptions;
at java.lang.Class.getDeclaredFields0(Native Method) [:1.8.0_112]
at java.lang.Class.privateGetDeclaredFields(Class.java:2583) [:1.8.0_112]
at java.lang.Class.getDeclaredFields(Class.java:1916) [:1.8.0_112]
at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.<init>(ClassReflectionIndex.java:57)
at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:66)
... 8 more
Caused by: java.lang.ClassNotFoundException: com.mongodb.MongoClientOptions from [Module "deployment.myapp-0.1.0.war:main" from Service Module Loader]
... 13 more
我的猜测 - Spring Boot会自动包含它。我试图将它排除在外:
@EnableAutoConfiguration(exclude=MongoAutoConfiguration.class)
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
但它没有效果。
我的build.gradle:
buildscript {
repositories {
jcenter()
mavenCentral()
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.7.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'application'
apply plugin: 'war'
sourceCompatibility = 1.6
targetCompatibility = 1.6
repositories {
jcenter()
mavenCentral()
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
}
dependencies {
compile "org.springframework.boot:spring-boot-starter-web:1.5.7.RELEASE"
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
}
war {
baseName = 'myapp'
version = '0.1.0'
}