我有在Wildfly 13上运行的Spring Boot应用,并且出现此错误
[org.jboss.msc.service.fail](ServerService线程池-75)MSC000001:无法启动服务jboss.undertow.deployment.default-server.default-host。” / naturallatex-rest-0.0。 1-SNAPSHOT“:服务jboss.undertow.deployment.default-server.default-host中的org.jboss.msc.service.StartException。” / naturallatex-rest-0.0.1-SNAPSHOT“:java.lang.RuntimeException:javax .servlet.ServletException:无法实例化WebApplicationInitializer类 在org.wildfly.extension.undertow.deployment.UndertowDeploymentService $ 1.run(UndertowDeploymentService.java:81) 在java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:511) 在java.util.concurrent.FutureTask.run(FutureTask.java:266) 在org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35) 在org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985) 在org.jboss.threads.EnhancedQueueExecutor $ ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487) 在org.jboss.threads.EnhancedQueueExecutor $ ThreadBody.run(EnhancedQueueExecutor.java:1378) 在java.lang.Thread.run(Thread.java:748) 在org.jboss.threads.JBossThread.run(JBossThread.java:485) 造成原因:java.lang.RuntimeException:javax.servlet.ServletException:无法实例化WebApplicationInitializer类 在io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:253) 在org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:96) 在org.wildfly.extension.undertow.deployment.UndertowDeploymentService $ 1.run(UndertowDeploymentService.java:78) ...另外8个 原因:javax.servlet.ServletException:无法实例化WebApplicationInitializer类 在org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:155) 在io.undertow.servlet.core.DeploymentManagerImpl $ 1.call(DeploymentManagerImpl.java:204) 在io.undertow.servlet.core.DeploymentManagerImpl $ 1.call(DeploymentManagerImpl.java:186) 在io.undertow.servlet.core.ServletRequestContextThreadSetupAction $ 1.call(ServletRequestContextThreadSetupAction.java:42) 在io.undertow.servlet.core.ContextClassLoaderSetupAction $ 1.call(ContextClassLoaderSetupAction.java:43) 在org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda $ create $ 0(SecurityContextThreadSetupAction.java:105) 在org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService $ UndertowThreadSetupAction.lambda $ create $ 0(UndertowDeploymentInfoService.java:1514) 在org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService $ UndertowThreadSetupAction.lambda $ create $ 0(UndertowDeploymentInfoService.java:1514) 在org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService $ UndertowThreadSetupAction.lambda $ create $ 0(UndertowDeploymentInfoService.java:1514) 在org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService $ UndertowThreadSetupAction.lambda $ create $ 0(UndertowDeploymentInfoService.java:1514) 在org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService $ UndertowThreadSetupAction.lambda $ create $ 0(UndertowDeploymentInfoService.java:1514) 在io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:251) ...还有10个 造成原因:java.lang.NoClassDefFoundError:org / springframework / boot / context / embedded / RegistrationBean 在java.lang.Class.getDeclaredConstructors0(本地方法) 在java.lang.Class.privateGetDeclaredConstructors(Class.java:2671) 在java.lang.Class.getConstructor0(Class.java:3075) 在java.lang.Class.newInstance(Class.java:412) 在org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:152) ...另外21个 引起原因:java.lang.ClassNotFoundException:[服务模块加载程序中的模块[deployment.naturallatex-rest-0.0.1-SNAPSHOT.war]中的org.springframework.boot.context.embedded.RegistrationBean。 在org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:255) 在org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:410) 在org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398) 在org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116) ...另外26个
这是POM.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>naturallatex</groupId>
<artifactId>naturallatex-rest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>naturallatex-rest</name>
<description></description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/joda-time/joda-time -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>1.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
配置分为2类
package naturallatex.config;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
public class WebAppInitializer implements WebApplicationInitializer {
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(AppConfig.class);
ctx.setServletContext(servletContext);
Dynamic dynamic = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
dynamic.addMapping("/");
dynamic.setLoadOnStartup(1);
}
}
这是第二个
package naturallatex.config;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import javax.sql.DataSource;
@EnableAutoConfiguration
@Configuration
@ComponentScan("naturallatex")
@EnableWebMvc
@EnableJpaRepositories("naturallatex.dao")
public class AppConfig {
@Bean
@ConfigurationProperties(prefix = "spring.datasource")
DataSource ds1() {
return DataSourceBuilder.create().build();
}
}
您能帮我吗,谢谢您