Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
__缺少第一个“阶段”[jboss.naming.context.java.app.earth.env.EarthDS]";]?_Java_Maven_Jakarta Ee_Jboss - Fatal编程技术网

__缺少第一个“阶段”[jboss.naming.context.java.app.earth.env.EarthDS]";]?

__缺少第一个“阶段”[jboss.naming.context.java.app.earth.env.EarthDS]";]?,java,maven,jakarta-ee,jboss,Java,Maven,Jakarta Ee,Jboss,我正在尝试部署我的javaee7应用程序。我有EntityManagerProduceras import javax.ejb.Singleton; import javax.ejb.Startup; import javax.enterprise.inject.Produces; import javax.persistence.EntityManager; import javax.persistence.PersistenceUnit; @Startup @Singleton publi

我正在尝试部署我的
javaee7
应用程序。我有
EntityManagerProducer
as

import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.enterprise.inject.Produces;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceUnit;

@Startup
@Singleton
public class PersistenceEntityManagerProducer {
    @PersistenceUnit(unitName = "earth")
    private EntityManager entityManager;

    @Produces
    @PersistenceEntityManager
    public EntityManager getEntityManager() {
        return entityManager;
    }
}  
我的
CrudService
as

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.inject.Inject;
import javax.persistence.EntityManager;

@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class CrudService {
    private EntityManager entityManager;

    @SuppressWarnings("UnusedDeclaration")
    public CrudService() {
    }

    @Inject
    public CrudService(@PersistenceEntityManager @Nonnull final EntityManager entityManager) {
        this.entityManager = entityManager;
    }

    @SuppressWarnings("UnusedDeclaration")
    @Nonnull
    public EntityManager getEntityManager() {
        return entityManager;
    }

    @Nonnull
    public <T> T create(@Nonnull final T entity) {
        entityManager.persist(entity);
        entityManager.flush();
        entityManager.refresh(entity);
        return entity;
    }

    @Nullable
    public <T> T find(final long id, final Class<T> classType) {
        return entityManager.find(classType, id);
    }

    public <T> void delete(@Nonnull final T entity) {
        entityManager.remove(entity);
    }
}
我尝试使用
maven-cargo-plugin
pom.xml
部署我的应用程序

<?xml version="1.0" encoding="UTF-8"?>
<persistence
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://java.sun.com/xml/ns/persistence"
        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
        version="2.0">
    <persistence-unit name="earth" transaction-type="JTA">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <jta-data-source>java:app/env/EarthDS</jta-data-source>
        <properties>
            <property name="hibernate.archive.autodetection" value="class"/>
            <property name="hibernate.id.new_generator_mappings" value="true"/>
            <property name="javax.persistence.lock.timeout" value="5000"/>
        </properties>
    </persistence-unit>
</persistence>
<?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">
    <parent>
        <artifactId>multi-persistence</artifactId>
        <groupId>com.learner</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>integration</artifactId>

    <dependencies>
        <dependency>
            <groupId>com.learner</groupId>
            <artifactId>services</artifactId>
            <version>${project.version}</version>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.180</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derby</artifactId>
            <version>10.10.2.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derbyclient</artifactId>
            <version>10.11.1.1</version>
            <scope>test</scope>
        </dependency>

    </dependencies>
    <properties>
        <maven.cargo.version>1.4.8</maven.cargo.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.carlspring.maven</groupId>
                <artifactId>derby-maven-plugin</artifactId>
                <version>1.8</version>
                <configuration>
                    <port>1527</port>
                </configuration>
                <executions>
                    <execution>
                        <id>start-derby</id>
                        <goals>
                            <goal>start</goal>
                        </goals>
                        <phase>pre-integration-test</phase>
                    </execution>
                    <execution>
                        <id>stop-derby</id>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                        <phase>post-integration-test</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <version>${maven.cargo.version}</version>
                <configuration>
                    <container>
                        <containerId>wildfly8x</containerId>
                        <dependencies combine.children="append">
                            <dependency>
                                <groupId>org.apache.derby</groupId>
                                <artifactId>derby</artifactId>
                            </dependency>
                            <dependency>
                                <groupId>org.apache.derby</groupId>
                                <artifactId>derbyclient</artifactId>
                            </dependency>
                        </dependencies>
                    </container>
                    <configuration>
                        <properties>
                            <cargo.servlet.port>9090</cargo.servlet.port>
                            <properties>
                                <cargo.datasource.datasource.derby>
                                    cargo.datasource.driver=org.apache.derby.jdbc.ClientDriver|
                                    cargo.datasource.url=jdbc:derby://localhost:1527/earth;create=true|
                                    cargo.datasource.jndi=app/env/EarthDS|
                                    cargo.datasource.username=APP|
                                    cargo.datasource.password=nonemptypassword
                                </cargo.datasource.datasource.derby>
                            </properties>
                            <!--<properties>
                                <cargo.datasource.datasource.h2>
                                    cargo.datasource.driver=org.h2.jdbcx.JdbcDataSource|
                                    cargo.datasource.url=jdbc:h2:earth|
                                    cargo.datasource.jndi=jdbc/EarthDS|
                                    cargo.datasource.username=sa|
                                    cargo.datasource.password=sa
                                </cargo.datasource.datasource.h2>
                            </properties>-->
                        </properties>
                    </configuration>
                    <deployables>
                        <deployable>
                            <groupId>com.learner</groupId>
                            <artifactId>services</artifactId>
                            <type>war</type>
                            <properties>
                                <context>earth</context>
                            </properties>
                        </deployable>
                    </deployables>
                </configuration>
                <executions>
                    <execution>
                        <id>start-container</id>
                        <goals>
                            <goal>start</goal>
                        </goals>
                        <phase>pre-integration-test</phase>
                    </execution>
                    <execution>
                        <id>stop-container</id>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                        <phase>post-integration-test</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>  

有人能告诉我出了什么问题吗?

错误信息非常清楚:

[信息][talledLocalContainer]JBAS014775:新的缺少/未满足的依赖项: [信息][talledLocalContainer]服务jboss.naming.context.java.app.earth.env.EarthDS(缺少)依赖项:[服务jboss.persistenceunit.“earth.war#earth”。第一阶段] [


是否创建了数据源?

您可以通过CLI(命令行界面)创建数据源 这就是我在JBOSS_HOME/standalone/configuration/standalone.xml中实现的方法

    <subsystem xmlns="urn:jboss:domain:datasources:1.0">
        <datasources>
            <datasource jndi-name="java:jboss/datasources/EarthDS" pool-name="EarthDS" enabled="true" use-ccm="true">
                <connection-url>jdbc:oracle:thin:@myhost:1521:MYDB</connection-url>
                <connection-property name="defaultNChar">
                    true
                </connection-property>
                <driver>ojdbc6.jar</driver>
                <new-connection-sql>alter session set current_schema=foobar</new-connection-sql>
                <pool>
                    <min-pool-size>20</min-pool-size>
                    <max-pool-size>300</max-pool-size>
                </pool>
                <security>
                    <user-name>username</user-name>
                    <password>passwd</password>
                </security>
                <timeout>
                    <idle-timeout-minutes>15</idle-timeout-minutes>
                </timeout>
            </datasource>
            <drivers>
                <driver name="h2" module="com.h2database.h2">
                    <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                </driver>
            </drivers>
        </datasources>
    </subsystem>

jdbc:oracle:thin:@myhost:1521:MYDB
真的
ojdbc6.jar
alter session set current_schema=foobar
20
300
用户名
passwd
15
org.h2.jdbcx.JdbcDataSource

您需要在standalone.xml中配置数据源,或在项目中创建-ds.xml数据源文件,如Jboss文档或mastertheboss页面中的说明。 例如:

您需要在数据源中输入以下名称:

java:app/env/EarthDS

因为您在persistence.xml上定义了它:

java:app/env/EarthDS

如果愿意,请在standalone.xml中定义数据源。以下是一个示例:

     <subsystem xmlns="urn:jboss:domain:datasources:2.0">
        <datasources>
            <datasource jndi-name="java:app/env/EarthDS" pool-name="EarthDS" enabled="true" use-java-context="true">
                <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
                <driver>h2</driver>
                <security>
                    <user-name>sa</user-name>
                    <password>sa</password>
                </security>
            </datasource>
            <drivers>
                <driver name="h2" module="com.h2database.h2">
                    <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                </driver>
            </drivers>
        </datasources>
    </subsystem>

jdbc:h2:mem:test;DB\u CLOSE\u DELAY=-1;DB\u CLOSE\u ON\u EXIT=FALSE
氢
sa
sa
org.h2.jdbcx.JdbcDataSource

注意:此示例与Jboss AS7/Wildfly兼容。

可以按照此答案中的说明创建数据源,但无论如何都没有帮助。
     <subsystem xmlns="urn:jboss:domain:datasources:2.0">
        <datasources>
            <datasource jndi-name="java:app/env/EarthDS" pool-name="EarthDS" enabled="true" use-java-context="true">
                <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
                <driver>h2</driver>
                <security>
                    <user-name>sa</user-name>
                    <password>sa</password>
                </security>
            </datasource>
            <drivers>
                <driver name="h2" module="com.h2database.h2">
                    <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                </driver>
            </drivers>
        </datasources>
    </subsystem>