jboss-javaee6-webapp上的种子数据导入失败

时间:2011-06-01 08:01:09

标签: java eclipse java-ee-6 archetypes seam3

我正在尝试使用基本的Seam 3 web应用程序来运行并使用jboss-javaee6-webapp来实现这一目标。使用http://seamframework.org/Documentation/CDIQuickstartForMavenUsers处的手册。

但是,我遇到了一些我几天都无法解决的问题。我基本上没有JavaEE的经验,因此解决方案可能非常简单。

我做了什么?我只是根据提供的原型生成了一个新的maven项目,并没有改变它的任何内容。我已经安装了Eclipse Helios,包括JBoss Tools和下载的JBoss 6.0.0,并让Eclipse成功地将应用程序部署到服务器。

部署时,示例代码中会发生异常。具体而言,会发生以下异常:

09:29:20,712 WARN  [seam3-example] Seed data import failed.: java.lang.NullPointerException
        at org.jboss.weld.integration.persistence.JBossJpaServices.resolvePersistenceContext(JBossJpaServices.java:59) [:6.0.0.Final]
    at org.jboss.weld.util.Beans.injectEEFields(Beans.java:781) [:6.0.0.Final]
    at org.jboss.weld.bean.ManagedBean$ManagedBeanInjectionTarget$1$1.proceed(ManagedBean.java:181) [:6.0.0.Final]
    at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:54) [:6.0.0.Final]
    at org.jboss.weld.bean.ManagedBean$ManagedBeanInjectionTarget$1.work(ManagedBean.java:176) [:6.0.0.Final]
    at org.jboss.weld.bean.ManagedBean$FixInjectionPoint.run(ManagedBean.java:142) [:6.0.0.Final]
    at org.jboss.weld.bean.ManagedBean$ManagedBeanInjectionTarget.inject(ManagedBean.java:170) [:6.0.0.Final]
    at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:339) [:6.0.0.Final]
    at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:67) [:6.0.0.Final]
    at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:669) [:6.0.0.Final]
    at org.jboss.weld.bean.AbstractReceiverBean.getReceiver(AbstractReceiverBean.java:84) [:6.0.0.Final]
    at org.jboss.weld.bean.ProducerField$1.produce(ProducerField.java:134) [:6.0.0.Final]
    at org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:361) [:6.0.0.Final]
    at org.jboss.weld.bean.builtin.ee.EEResourceProducerField.createUnderlying(EEResourceProducerField.java:170) [:6.0.0.Final]
    at org.jboss.weld.bean.builtin.ee.EEResourceProducerField.access$000(EEResourceProducerField.java:54) [:6.0.0.Final]
    at org.jboss.weld.bean.builtin.ee.EEResourceProducerField$EEResourceCallable.call(EEResourceProducerField.java:80) [:6.0.0.Final]
    at org.jboss.weld.bean.builtin.CallableMethodHandler.invoke(CallableMethodHandler.java:50) [:6.0.0.Final]
    at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:62) [:6.0.0.Final]
    at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:125) [:6.0.0.Final]
    at org.jboss.weldx.persistence.org$jboss$weld$bean-jboss$classloader:id="vfs:$$$Users$sander$Workspaces$eclipse$web-dev-32$$metadata$$plugins$org$jboss$ide$eclipse$as$core$JBoss_6$0_Runtime_Server1306911969901$deploy$seam3-example$war"-ProducerField-nl$jdi$examples$data$MemberRepositoryProducer$em_$$_WeldProxy.persist(org$jboss$weld$bean-jboss$classloader:id="vfs:$$$Users$sander$Workspaces$eclipse$web-dev-32$$metadata$$plugins$org$jboss$ide$eclipse$as$core$JBoss_6$0_Runtime_Server1306911969901$deploy$seam3-example$war"-ProducerField-nl$jdi$examples$data$MemberRepositoryProducer$em_$$_WeldProxy.java)
    at nl.jdi.examples.data.SeedDataImporter.importData(SeedDataImporter.java:51) [:]
...

我已经为这个确切的异常搜索了一个解决方案,但我几乎找不到任何关于它的信息。这可能意味着我忽略了一些非常简单的事情。所以我分析了异常,发现了以下内容:

  1. 异常消息来自示例代码(SeedDataImporter.java:61)
  2. 异常本身(NullPointer)在焊接代码中被抛出
  3. 问题似乎与纯粹持久性有关(它找不到PersistenceContext?)
  4. 由于问题与持久性有关,我试图更改persistence.xml但是这没有付出代价。我认为问题出在JDNI / Persistence.xml / Server配置域中,但我无法确定。

    有人能指出我正确的方向吗?

    的persistence.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="2.0" 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">
    <persistence-unit name="primary">
        <jta-data-source>jdbc/__default</jta-data-source>
        <properties>
            <!-- Properties for Hibernate (default provider for JBoss AS) -->
            <property name="hibernate.hbm2ddl.auto" value="create-drop" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="false" />
            <!-- Properties for EclipseLink (default provider for GlassFish) -->
            <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
            <property name="eclipselink.logging.level" value="FINE" />
        </properties>
    </persistence-unit>
    

    修改

    当我尝试在Eclipse中将未更改的应用程序部署到GlassFish 3.1时,我收到以下错误:

    cannot Deploy seam3-example
    Deployment Error for module: seam3-example: Error occurred during deployment: Exception while loading the app : javax.ejb.CreateException: Initialization failed for Singleton SeedDataImporter. Please see server.log for more details.
    
    Cannot create tables for application seam3-example. The expected DDL file seam3-example_primary_createDDL.jdbc is not available.
    
    Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused.
    

3 个答案:

答案 0 :(得分:1)

我认为这是一个persistance.xml问题,因为你有:

<jta-data-source>jdbc/__default</jta-data-source>

这是Glassfish AS的默认值

试试这个:

<jta-data-source>java:/DefaultDS</jta-data-source> 

这是JBoss的默认值

您是否在默认域中运行JBoss AS?

答案 1 :(得分:0)

至少在命令行上我可以开始这样做:

  1. 下载并安装最新的jboss 6到
  2. mvn archetype:generate -DarchetypeArtifactId=jboss-javaee6-webapp -DarchetypeGroupId=org.jboss.weld.archetypes -DarchetypeVersion=1.0.1.CR1 -DarchetypeRepository=central -DgroupId=com.example -DartifactId=jee-example -Dversion=0.0.1-SNAPSHOT
  3. cd jee-example
  4. mvn clean package jboss:hard-deploy -Djboss.home=<jboss-6.0.0.Final>
  5. 使用<jboss-6.0.0.Final>/bin/run.sh(Windws上的run.bat)启动jboss
  6. 打开http://localhost:8080/jee-example/
  7. 有关详细信息,请查看由archtype在与pom.xml相同的文件夹中创建的readme.html

    要在eclipse中工作,你应该安装

    1. eclipse for Java EE Developers
    2. 来自此更新站点的m2eclipse
    3. 来自m2eclipse-extra更新站点documentation
    4. 的m2eclipse wtp扩展

      我没有尝试原型部分的原型......

答案 2 :(得分:0)

如果您检查原型生成的persistence.xml文件,您会看到以下评论:

<!-- A matching data source is added to JBoss AS by deploying the project file default-ds.xml -->
<jta-data-source>jdbc/__default</jta-data-source>

resources-jbossas内部有一个default-ds.xml文件,您应该将其部署到JBoss,以便能够在不更改任何代码的情况下使用该应用程序。