Wildfly Swarm主要没有启动EJB

时间:2017-04-10 06:00:01

标签: java java-ee wildfly-swarm

我正在学习过去两天使用wildfly swarm构建微服务的概念,并使用EJB,JAX-RS,CDI和JPA设置一些服务来测试一些Java EE功能。该服务正在运行,但仅当我不使用Main类并且pom.xml中的包装设置为 war 时。

如果我使用Main类添加其他分数,则服务无法正常启动,EJB未在JNDI中部署和使用。

使用?

启动JAX-RS服务的正确方法是什么?

的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>

    <parent>
        <artifactId>microservice-playground</artifactId>
        <groupId>cgh</groupId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>

    <artifactId>user-service</artifactId>
    <packaging>war</packaging>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.wildfly.swarm</groupId>
            <artifactId>jaxrs</artifactId>
        </dependency>
        <dependency>
            <groupId>org.wildfly.swarm</groupId>
            <artifactId>ejb</artifactId>
        </dependency>
        <dependency>
            <groupId>org.wildfly.swarm</groupId>
            <artifactId>jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.wildfly.swarm</groupId>
            <artifactId>cdi</artifactId>
        </dependency>
    </dependencies>

    <build>
        <finalName>user-service</finalName>
        <plugins>
            <plugin>
                <groupId>org.wildfly.swarm</groupId>
                <artifactId>wildfly-swarm-plugin</artifactId>
                <configuration>
                    <mainClass>cgh.user.Main</mainClass>
                    <properties>
                        <swarm.context.path>${project.build.finalName}</swarm.context.path>
                    </properties>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>package</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

主要课程:

public class Main {
    public static void main(String[] args) throws Exception {
        Swarm swarm = new Swarm();
        swarm.start();

        JAXRSArchive archive = ShrinkWrap.create(JAXRSArchive.class);
        archive.addPackage(Main.class.getPackage());
        archive.addAsWebInfResource(new ClassLoaderAsset("META-INF/persistence.xml", Main.class.getClassLoader()),
            "classes/META-INF/persistence.xml");
        archive.addAllDependencies();

        swarm.deploy(archive);
    }
}

0 个答案:

没有答案