I am trying to get a basic Seam 3 webapplication to work and use the jboss-javaee6-webapp to achieve this goal. Using the manual at http://seamframework.org/Documentation/CDIQuickstartForMavenUsers.
However, I am running into some problems which I haven't been able to solve for days. I have basically no experience in JavaEE so the solution is probably really easy.
What I've done? I've simply generated a new maven project based on the supplied archetype and didn't change anything about it. I've installed Eclipse Helios including JBoss Tools and downloaded JBoss 6.0.0 and got Eclipse to deploy the application to the server succesfully.
While deploying, an exception occurs in the example code. To be specific the following exceptions occurs:
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 or开发者_StackOverflow中文版g.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) [:]
...
I've searched for a solution for this exact exception but I could barely find anything about it. This probably means that I've overlooked something very simple. So I've analysed the exception and found the following:
- The exception message is from the example code (SeedDataImporter.java:61)
- The exception itself (NullPointer) is thrown somewhere in the weld code
- The problem seems to be purely persistence related (it can't find the PersistenceContext?)
Since the problem is persistence related, I've tried to change the persistence.xml however this didn't pay out. I think the problem is within the JDNI/Persistence.xml/Server config domain, however I can't be sure.
Can anybody point me in the right direction?
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>
Edit:
When I try to deploy the unchanged application to GlassFish 3.1 within Eclipse I get the following error:
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.
I think it is a persistance.xml problem because you have:
<jta-data-source>jdbc/__default</jta-data-source>
and this is default for Glassfish AS
Try this:
<jta-data-source>java:/DefaultDS</jta-data-source>
This is default for JBoss
Do you run JBoss AS in default domain?
If you check the persistence.xml
file generated by the archetype, you'll see this comment:
<!-- 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>
Inside resources-jbossas
there's a default-ds.xml
file that you should deploy to JBoss in order to be able to use the app without any code changes.
At least on the command line I can start the example doing this:
- Download and install the latest jboss 6 to
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
- cd jee-example
mvn clean package jboss:hard-deploy -Djboss.home=<jboss-6.0.0.Final>
- start the jboss with
<jboss-6.0.0.Final>/bin/run.sh
(run.bat on Windws) - open
http://localhost:8080/jee-example/
For more details have a look at the readme.html that is created by the archtype in the same folder as the pom.xml
To work in eclipse you should install
- eclipse for Java EE Developers
- m2eclipse from this update site
- m2eclipse wtp extension from the m2eclipse-extra update site documentation
I did not try the eclipse part for the archetype...
精彩评论