我正在尝试运行一个具有Weld实现CDI的独立应用程序,在该应用程序中我需要EntityManager来使用Oracle数据库。
当我运行我的应用程序时(通过Weld main方法),以下内容显示在cmd行中:
Exception in thread "main" java.lang.IllegalAccessError: tried to access class javax.xml.parsers.FactoryFinder from class javax.xml.parsers.FactoryFinder$ConfigurationError
at java.lang.Class.getDeclaringClass0(Native Method)
at java.lang.Class.getDeclaringClass(Unknown Source)
at java.lang.Class.getEnclosingClass(Unknown Source)
at java.lang.Class.getSimpleBinaryName(Unknown Source)
at java.lang.Class.isMemberClass(Unknown Source)
at org.jboss.weld.util.reflection.Reflections.isNonStaticInnerClass(Reflections.java:139)
at org.jboss.weld.bootstrap.BeanDeployer.isBeanCandidate(BeanDeployer.java:98)
at org.jboss.weld.bootstrap.BeanDeployer.addClass(BeanDeployer.java:78)
at org.jboss.weld.bootstrap.BeanDeployer.addClasses(BeanDeployer.java:135)
at org.jboss.weld.bootstrap.BeanDeployment.createBeans(BeanDeployment.java:184)
at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:349)
at org.jboss.weld.bootstrap.api.helpers.ForwardingBootstrap.deployBeans(ForwardingBootstrap.java:70)
at org.jboss.weld.environment.se.Weld.initialize(Weld.java:133)
at org.jboss.weld.environment.se.StartMain.go(StartMain.java:41)
at org.jboss.weld.environment.se.StartMain.main(StartMain.java:52)
什么可能导致这样的错误?
这是我的persistence.xml:
<persistence-unit name="oracleUnit"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>entities.MyEntity</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver" />
<property name="javax.persistence.jdbc.platform"
value="org.eclipse.persistence.platform.database.oracle.OraclePlatform" />
<property name="javax.persistence.jdbc.url"
value="jdbc:oracle:thin:@localhost:1521:orcl" />
<property name="javax.persistence.jdbc.user" value="TEST" />
<property name="javax.persistence.jdbc.password" value="test" />
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
</properties>
</persistence-unit>
以下是依赖项:
<dependencies>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<version>1.1.10.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.8.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.8.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.3.Final</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
以下是我创建实体管理器的方法,相当标准:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("oracleUnit");
EntityManager em = emf.createEntityManager();
答案 0 :(得分:0)
将Weld依赖关系更新到最新版本解决了这个问题。
依赖关系现在看起来如下:
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<version>3.0.0.Alpha14</version>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jandex</artifactId>
<version>1.2.2.Final</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.8.Final</version>
</dependency>