Openshift没有部署persistence.xml?

时间:2015-05-30 11:00:57

标签: java jpa openshift wildfly persistence.xml

你好互联网社区,

所以我进入JAVA并开始在我的WildFly 8上测试一些东西。对于maven web项目,一切都很好,外观和工作都很好。现在我决定将openshift作为JAVA免费云的首选。我设法做了所有需要让我的日食和环境工作/上传/更新服务器。然后我决定用JPA / Hibernate添加MySQL,localy一切正常。但是,当我上传到openshift时,我收到以下错误:


2015-05-30 06:18:13,289 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.deployment.unit."ROOT.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."ROOT.war".WeldStartService: Failed to start service
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_45]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_45]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_45]
Caused by: java.lang.IllegalArgumentException: JBAS016069: Error injecting persistence unit into CDI managed bean. Can't find a persistence unit named  in deployment ROOT.war
    at org.jboss.as.weld.services.bootstrap.WeldJpaInjectionServices.getScopedPUName(WeldJpaInjectionServices.java:110)
    at org.jboss.as.weld.services.bootstrap.WeldJpaInjectionServices.registerPersistenceContextInjectionPoint(WeldJpaInjectionServices.java:73)
    at org.jboss.weld.injection.ResourceInjectionFactory$PersistenceContextResourceInjectionProcessor.getResourceReferenceFactory(ResourceInjectionFactory.java:313)
    at org.jboss.weld.injection.ResourceInjectionFactory$PersistenceContextResourceInjectionProcessor.getResourceReferenceFactory(ResourceInjectionFactory.java:301)
    at org.jboss.weld.injection.ResourceInjectionFactory$ResourceInjectionProcessor.createFieldResourceInjection(ResourceInjectionFactory.java:207)
    at org.jboss.weld.injection.ResourceInjectionFactory$ResourceInjectionProcessor.createResourceInjections(ResourceInjectionFactory.java:182)
    at org.jboss.weld.injection.ResourceInjectionFactory.discoverType(ResourceInjectionFactory.java:405)
    at org.jboss.weld.injection.ResourceInjectionFactory.getResourceInjections(ResourceInjectionFactory.java:92)
    at org.jboss.weld.injection.producer.ResourceInjector.(ResourceInjector.java:59)
    at org.jboss.weld.injection.producer.ResourceInjector.of(ResourceInjector.java:49)
    at org.jboss.weld.injection.producer.BeanInjectionTarget.(BeanInjectionTarget.java:62)
    at org.jboss.weld.injection.producer.BeanInjectionTarget.createDefault(BeanInjectionTarget.java:46)
    at org.jboss.weld.manager.InjectionTargetFactoryImpl.chooseInjectionTarget(InjectionTargetFactoryImpl.java:128)
    at org.jboss.weld.manager.InjectionTargetFactoryImpl.createInjectionTarget(InjectionTargetFactoryImpl.java:87)
    at org.jboss.weld.bean.ManagedBean.(ManagedBean.java:91)
    at org.jboss.weld.bean.ManagedBean.of(ManagedBean.java:71)
    at org.jboss.weld.bootstrap.AbstractBeanDeployer.createManagedBean(AbstractBeanDeployer.java:264)
    at org.jboss.weld.bootstrap.BeanDeployer.createClassBean(BeanDeployer.java:228)
    at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$2.doWork(ConcurrentBeanDeployer.java:78)
    at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$2.doWork(ConcurrentBeanDeployer.java:75)
    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60)
    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [rt.jar:1.8.0_45]
    ... 3 more

你可以看到错误来自

JBAS016069: Error injecting persistence unit into CDI managed bean. Can't find a persistence unit named  in deployment ROOT.war

这是我的PersistenceContext注入点:

<pre><code>
@SessionScoped
public class IndexWebBean implements Serializable {
private static final long serialVersionUID = 1L;

@PersistenceContext
EntityManager em;

@Inject
SettingsBean settingsBean;

private boolean isUserAdmin = true;

private String selectedTheme = "aristo";
private String aboutMessage;

private NotificationController notificationController;
public IndexWebBean() {}

@PostConstruct
public void Init() {}
}
</code></pre>

这里是persistence.xml:

<pre><code>
    <persistence-unit name="ROOT">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>java:jboss/datasources/MySQLDS</jta-data-source>
    <class>ROOT.ROOT.entity.User</class>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>            
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
        <property name="hibernate.hbm2ddl.auto" value="update" />
        <property name="hibernate.show_sql" value="false" />
        <property name="hibernate.format_sql" value="true" />
        <property name="hibernate.connection.useUnicode" value="true" />
        <property name="hibernate.connection.characterEncoding" value="UTF-8" />
    </properties>
</persistence-unit>
</code></pre>

standalone.xml:

<pre><code>
<datasources>
            <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" 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>
            <datasource jta="true" jndi-name="java:jboss/datasources/MySQLDS" pool-name="MySQL" enabled="true" use-ccm="true">
                <connection-url>jdbc:mysql://localhost:3306/crafty</connection-url>
                <driver-class>com.mysql.jdbc.Driver</driver-class>
                <driver>com.mysql</driver>
                <security>
                    <user-name>XX</user-name>
                    <password>XX</password>
                </security>
                <validation>
                    <validate-on-match>false</validate-on-match>
                    <background-validation>false</background-validation>
                </validation>
                <timeout>
                    <set-tx-query-timeout>false</set-tx-query-timeout>
                    <blocking-timeout-millis>0</blocking-timeout-millis>
                    <idle-timeout-minutes>0</idle-timeout-minutes>
                    <query-timeout>0</query-timeout>
                    <use-try-lock>0</use-try-lock>
                    <allocation-retry>0</allocation-retry>
                    <allocation-retry-wait-millis>0</allocation-retry-wait-millis>
                </timeout>
                <statement>
                    <share-prepared-statements>false</share-prepared-statements>
                </statement>
            </datasource>
            <drivers>
                <driver name="h2" module="com.h2database.h2">
                    <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                </driver>
                <driver name="com.mysql" module="com.mysql"/>
            </drivers>
</datasources>
</code></pre>

(很多文字都已经过时,所以快速提醒:localy eveyrthing就像魅力一样)

所以我选择&#34; rhc ssh -a appname&#34;并检查在wildfly / standalone / deployments / ROOT.war中是否在独立的WAR文件中编译,而在本地系统中整个项目是基于文件夹的 - 它没有编译为WAR。这不是特别糟糕的事情,但重点是当我解压WAR时,我检查了文件夹结构是否与本地文件夹结构相同。似乎不是。在ROOT.war / WEB-INF / classes中没有META-INF,其中persistence.xml实际上就是......这是一个奇怪的!我做的是将@PersistenceContext(unitName =&#34; ROOT&#34;)添加到em注入点,手动创建该文件夹(META-INF),从本地计算机手动上传我的persistence.xml,并重命名ROOT.war 。无法通过ROOT.war.dodeply重新部署,而且工作正常。但后来我对代码localy进行了一些更改,再次它就像一个魅力,通过eclipse发布到openshift并且仍然openhift将我的ROOT.war编译为webarch并且META-INF和standalone.xml无处可寻找但是导致同样的错误。所以我的问题是:如果一切都很好,那么我做错了什么,并且上传到openshift时没有?提前感谢您的时间。

PS:对于任何错误,英语不是我原生的抱歉。我希望一切都是可读的和易懂的。我将根据需要提供更多其他信息。

0 个答案:

没有答案