我正在尝试运行一个具有 CDI 焊接实现的独立应用程序,并且在该应用程序中我需要 EntityManager 来使用 Oracle 数据库。
当我运行我的应用程序(通过 Weld 主方法)时,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();