如何在wildfly中引导Spring Boot应用程序?

时间:2016-10-13 14:21:37

标签: java spring spring-boot wildfly-9

我在Spring中构建了一个应用程序,并希望在wildfly中运行它。它不是一个webapp,所以包装是jar。

启动时,jboss报告已加载它:

14:50:42,899 INFO  [org.jboss.weld.deployer] (MSC service thread 1-2) WFLYWELD0003: Processing weld deployment APPLICATION_cnp.jar
14:50:42,949 INFO  [org.jboss.weld.deployer] (MSC service thread 1-2) WFLYWELD0006: Starting Services for CDI deployment: cnp.ear
14:50:43,031 INFO  [org.jboss.weld.Version] (MSC service thread 1-2) WELD-000900: 2.2.16 (SP1)
14:50:43,066 INFO  [org.jboss.weld.deployer] (MSC service thread 1-3) WFLYWELD0009: Starting weld service for deployment cnp.ear
14:50:45,517 INFO  [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0010: Deployed "cnp.ear" (runtime-name : "cnp.ear")

该应用程序的入口点是这个类:

//@Configuration
//@ComponentScan
//@EnableAutoConfiguration
//3 above added as per https://stackoverflow.com/questions/35786401/
@SpringBootApplication
//3 below added to try and get java EE to bootstrap the app
//@Startup
//@Singleton
//@ApplicationScoped
public class CNPApplication {

private static final Logger log = LoggerFactory.getLogger(CNPApplication.class);

public static void main(String[] args) throws Exception {
    SpringApplication.run(CNPApplication.class);
}

public CNPApplication() {
    System.out.println("CNPApplication instantiated");
}

@PostConstruct
public void bootstrap() {
    System.out.println("CNPApplication bootstrap");
    SpringApplication.run(CNPApplication.class);

}

}

我的pom文件如下所示:

<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>com.mycompany</groupId>
<artifactId>APPLICATION_cnp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>APPLICATION_cnp</name>
<description>Courtesy Notification Processor</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.1.RELEASE</version>
    <relativePath/> 
</parent>

<properties>
    <java.version>1.8</java.version>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source>
</properties>

<dependencies>
   <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>7.0</version>
        <scope>compile</scope>
    </dependency>
</dependencies>

我已将其部署为EAR的一部分。 wildfly管理控制台显示名为cnp.ear的部署,具有嵌套部署APPLICATION_cnp.jar

System.out.println类中的CNPApplication次调用未被调用。我已经尝试了类顶部的所有注释,并且我尝试添加了beans.xml。添加了beans.xml后,我在启动时获得了一个堆栈跟踪:Unable to resolve a bean for 'javax.persistence.EntityManager' - This link建议我通过删除beans.xml来解决这个问题,因为它会导致JAVA EE CDI与spring发生冲突。

我如何实际运行?

0 个答案:

没有答案