在Openshift上部署应用程序时出错

时间:2012-07-12 14:18:38

标签: mysql spring java-ee jboss openshift

我之前没有部署在jboss应用服务器上。尝试在openshift上部署Java Web应用程序时出现以下错误。我使用的是SpringJPA 2.0

我的applicationContext.xml

<jee:jndi-lookup id="dataSource" jndi-name="java:jboss/datasources/MysqlDS" resource-ref="true" />

我的standalone.xml

<datasource jndi-name="java:jboss/datasources/MysqlDS" enabled="${mysql.enabled}" use-java-context="true" pool-name="MysqlDS">
                    <connection-url>jdbc:mysql://${env.OPENSHIFT_DB_HOST}:${env.OPENSHIFT_DB_PORT}/${env.OPENSHIFT_APP_NAME}</connection-url>
                    <driver>mysql</driver>
                    <security>
                      <user-name>${env.OPENSHIFT_DB_USERNAME}</user-name>
                      <password>${env.OPENSHIFT_DB_PASSWORD}</password>
                    </security>
                </datasource>
                <drivers>
                    <driver name="mysql" module="com.mysql.jdbc">
                        <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
                    </driver>
                </drivers>

错误

2012/07/12 09:00:36,714 INFO  [org.hibernate.ejb.Ejb3Configuration] (MSC service thread 1-2) HHH000204: Processing PersistenceUnitInfo [
    name: tentacleSpotPU
   ...]
2012/07/12 09:00:37,118 WARN  [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator] (MSC service thread 1-2) HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections
2012/07/12 09:00:37,139 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC00001: Failed to start service jboss.persistenceunit."ROOT.war#tentacleSpotPU": org.jboss.msc.service.StartException in service jboss.persistenceunit."ROOT.war#tentacleSpotPU": Failed to start service
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.6.0_24]
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.6.0_24]
   at java.lang.Thread.run(Thread.java:679) [rt.jar:1.6.0_24]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: tentacleSpotPU] Unable to build EntityManagerFactory
   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889)
   at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85)
   at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
   at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    ... 3 more
Caused by: org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set
   at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:97)
 at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:67)
 at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:176)
    at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
  at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
 at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71)
    at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2270)
  at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2266)
  at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1735)
    at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:84)
   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)
   ... 9 more

2012/07/12 09:00:37,309 ERROR [org.jboss.as] (MSC service thread 1-3) JBAS015875: JBoss AS 7.1.0.Final "Thunder" started (with errors) in 75169ms - Started 401 of 720 services (203 services failed or missing dependencies, 113 services are passive or on-demand)
2012/07/12 09:00:37,440 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015870: Deploy of deployment "ROOT.war" was rolled back with failure message {"JBAS014671: Failed services" => {"jboss.persistenceunit.\"ROOT.war#tentacleSpotPU\"" => "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"ROOT.war#tentacleSpotPU\": Failed to start service"}}
2012/07/12 09:00:38,574 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015877: Stopped deployment ROOT.war in 1131ms
2012/07/12 09:00:38,576 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report
JBAS014777:   Services which failed to start:      service jboss.persistenceunit."ROOT.war#tentacleSpotPU": org.jboss.msc.service.StartException in service jboss.persistenceunit."ROOT.war#tentacleSpotPU": Failed to start service

2012/07/12 09:00:38,609 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) {"JBAS014653: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"JBAS014671: Failed services" => {"jboss.persistenceunit.\"ROOT.war#tentacleSpotPU\"" => "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"ROOT.war#tentacleSpotPU\": Failed to start service"}}}}

我需要做些什么才能解决此问题?

3 个答案:

答案 0 :(得分:0)

您的项目如何设置?该项目是否使用jboss 7.1.0 Final在本地运行?我使用persistence.xml文件为我的JPA 2.0配置定义了我的EntityManagerFactory和hibernate.dialect。位于我的META-INF目录中。这就是我在项目中设置的方式。

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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="userpersistence" transaction-type="RESOURCE_LOCAL">
    <provider>
        org.hibernate.ejb.HibernatePersistence
    </provider>
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
        <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
        <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/acctdatabase"/>
        <property name="hibernate.connection.username" value="acct-user"/>
        <property name="hibernate.connection.password" value="password"/>
    </properties>
</persistence-unit>

答案 1 :(得分:0)

您应该尝试设置hibernate.dialect属性以允许JBoss在没有连接的情况下加载持久化上下文(它可以使用连接来检测方言)。它将等待从应用程序获得连接(在您的情况下为Spring)。

您可以在persistence.xml中设置它,或者可以在放置在类路径的根目录中的hibernate.properties中设置它

答案 2 :(得分:0)

我得到了同样的例外。 3-4天后,我意识到我的persistance.xml的位置不正确。我有使用EJB,JSF,MAVEN,MYSQL的EAR Web应用程序。所以,在我的日食中,我有ejb项目,web项目,ear项目和主项目。我正在更新persistance.xml文件,该文件位于EJB项目下的META-INF文件夹中。但是,我忘了在Web Project undre JPA Content中更新相同的内容。因此,您将在Web项目的META-INF文件夹下找到相同的persistance.xml文件。默认情况下,unit-name将是'project-name-web'和类。所以,更新那个与你在这里提到的相同,包括jta-datasource到属性。它应该工作。 我正在工作。最后。呼!