无法在Wildfly 8 AS中部署Spring Boot应用,请求协助
Hey there! Let's troubleshoot your Spring Boot WAR deployment issue on Wildfly 8. Since your app runs perfectly on embedded Tomcat, the problem is almost certainly tied to dependency conflicts or Wildfly-specific configuration mismatches. Here's a step-by-step breakdown to fix this:
1. Resolve Dependency Conflicts in pom.xml
Wildfly 8 ships with its own set of core libraries (like JBoss Logging instead of Logback, and its own Servlet API implementation), so we need to exclude Spring Boot dependencies that clash with these:
Update your spring-boot-starter-web dependency to exclude the default logging starter (along with the Tomcat starter you already removed):
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> <!-- Exclude Spring Boot's default logging to avoid conflict with Wildfly's JBoss Logging --> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency>
Add the JBoss Logging dependency to align with Wildfly's logging setup (this ensures smoother logging integration):
<dependency> <groupId>org.jboss.logging</groupId> <artifactId>jboss-logging</artifactId> <scope>provided</scope> </dependency>
2. Add a Wildfly-Specific Deployment Descriptor
Create a jboss-deployment-structure.xml file in src/main/webapp/WEB-INF/ to tell Wildfly to skip its own conflicting libraries:
<?xml version="1.0" encoding="UTF-8"?> <jboss-deployment-structure> <deployment> <exclude-subsystems> <subsystem name="logging"/> </exclude-subsystems> <exclusions> <!-- Exclude server-provided dependencies that clash with Spring Boot --> <module name="javax.servlet.api"/> <module name="org.slf4j"/> <module name="org.apache.commons.logging"/> </exclusions> <dependencies> <!-- Include required Wildfly modules for Spring Boot --> <module name="javax.persistence.api" export="true"/> </dependencies> </deployment> </jboss-deployment-structure>
3. Double-Check Your Application Entry Point
Your DemoApplication class already extends SpringBootServletInitializer—that's exactly what we need for WAR deployment on a Servlet container. Just confirm the configure method is correctly pointing to your app source:
@Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(DemoApplication.class); }
This ensures Wildfly can properly bootstrap your Spring Boot application.
4. Check Wildfly Logs for Exact Errors
If the above steps don't resolve the issue, dig into Wildfly's server.log (usually located in wildfly-8.x.x/standalone/logs/) for specific exceptions. Common culprits include:
- Missing dependencies that Wildfly expects
- Version mismatches for Java EE APIs
- Classloading conflicts (the deployment descriptor above should mitigate most of these)
5. Deploy the WAR Correctly
Build your WAR using Maven with mvn clean package, then drop the generated WAR file into Wildfly's standalone/deployments/ directory. You can also use the Wildfly management console to deploy and verify the deployment status.
Once deployed, your endpoint should be accessible at http://<wildfly-host>:8080/demo-0.0.1-SNAPSHOT/hello/sayHello (adjust the path to match your WAR filename).
内容的提问来源于stack exchange,提问作者Anirban

