- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我将 Java EE DAL 设置为 jar 库。我使用JPA + Hibernate + C3P0进行连接池管理。 EntityManager
类由以下 bean 生成
package my.dal;
import javax.enterprise.inject.Alternative;
import javax.enterprise.inject.Default;
import javax.enterprise.inject.Produces;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.PersistenceContext;
@Alternative
@Default
public class EntityManagerProvider {
private EntityManager entityManager;
@Default
@Produces
@PersistenceContext
public EntityManager getEntityManager() {
if(entityManager == null) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("DALPersistenceUnit");
entityManager = emf.createEntityManager();
}
return entityManager;
}
}
然后,DAO 类注入(inject) EntityManager 并使用它
package my.dal.dao;
@Default
public class UserDAO {
@Inject private EntityManager entityManager;
public User find(String username)
{
...
}
...
}
这些是在 pom.xml
中设置的 C3P0 依赖项
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.2.1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>4.3.5.Final</version>
</dependency>
<dependency>
<groupId>com.mchange</groupId>
<artifactId>mchange-commons-java</artifactId>
<version>0.2.3.4</version>
</dependency>
我编写了一个测试类(名为DALUserTest
),它注入(inject) DAO 类并使用它在数据库上保存数据。问题是,每当我尝试运行测试时,应用程序都会在注入(inject)步骤停止并抛出以下异常堆栈
javax.enterprise.inject.CreationException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.jboss.weld.security.NewInstanceAction.run(NewInstanceAction.java:33)
at java.security.AccessController.doPrivileged(Native Method)
at org.jboss.weld.injection.Exceptions.rethrowException(Exceptions.java:40)
at org.jboss.weld.injection.Exceptions.rethrowException(Exceptions.java:78)
at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:101)
at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstance(MethodInjectionPoint.java:86)
at org.jboss.weld.injection.producer.ProducerMethodProducer.produce(ProducerMethodProducer.java:96)
at org.jboss.weld.injection.producer.AbstractMemberProducer.produce(AbstractMemberProducer.java:151)
at org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:183)
at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:69)
at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:733)
at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:789)
at org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:92)
at org.jboss.weld.util.Beans.injectBoundFields(Beans.java:358)
at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:369)
at org.jboss.weld.injection.producer.DefaultInjector.inject(DefaultInjector.java:72)
at org.jboss.weld.injection.producer.ResourceInjector.inject(ResourceInjector.java:60)
at org.jboss.weld.injection.producer.DefaultInjector$1.proceed(DefaultInjector.java:66)
at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:48)
at org.jboss.weld.injection.producer.DefaultInjector.inject(DefaultInjector.java:64)
at org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:90)
at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:150)
at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:69)
at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:733)
at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:789)
at org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:92)
at org.jboss.weld.util.Beans.injectBoundFields(Beans.java:358)
at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:369)
at org.jboss.weld.injection.producer.DefaultInjector.inject(DefaultInjector.java:72)
at org.jboss.weld.injection.producer.ResourceInjector.inject(ResourceInjector.java:60)
at org.jboss.weld.injection.producer.DefaultInjector$1.proceed(DefaultInjector.java:66)
at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:48)
at org.jboss.weld.injection.producer.DefaultInjector.inject(DefaultInjector.java:64)
at org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:90)
at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:150)
at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:96)
at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:98)
at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:78)
at my.dal.test.DALUserTest$Proxy$_$$_WeldClientProxy.testInsert(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.jglue.cdiunit.CdiRunner$2.evaluate(CdiRunner.java:139)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.NoClassDefFoundError: com/mchange/v2/log/MLog
at com.mchange.v2.c3p0.DataSources.<clinit>(DataSources.java:72)
at org.hibernate.c3p0.internal.C3P0ConnectionProvider.configure(C3P0ConnectionProvider.java:203)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:399)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:75)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at my.dal.EntityManagerProvider.getEntityManager(EntityManagerProvider.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:93)
... 58 more
Caused by: java.lang.ClassNotFoundException: com.mchange.v2.log.MLog
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 83 more
我用谷歌搜索了很多,但没有任何帮助我解决这个问题。您认为问题可能出在哪里?
谢谢
最佳答案
下载mchange-commons-java-0.2.16.jar解决错误java.lang.NoClassDefFoundError: com/mchange/v2/log/MLog
关于java - C3P0 + Hibernate ClassNotFoundException : com. mchange.v2.log.MLog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24065450/
我的应用在尝试访问外部依赖项时遇到 NoClassDefFoundError,但仅限于作为 jar 运行时。 使用 Intellij,我有一个带有主类的简单应用程序,其中包含一些对外部依赖项(例如 s
我收到以下异常: java.lang.ClassNotFoundException: org.jboss.resteasy.plugins.server.servlet.ResteasyBootstr
我正在尝试使用eclipse和tomcat调试solr4.6源代码。我收到错误消息:HTTP 状态 500 - {msg=SolrCore 'collection1' 由于初始化失败而不可用:[sch
我是新来的,很抱歉我的英语不好;)。 我尝试使用以下代码在 java 中加载插件 jar: package testprogramm; import java.io.File; import java
我重新安装了 ADT Bundle,因为我在更新 eclipse 后遇到了一些问题。 现在,当我想测试我的应用程序时,出现以下异常: 06-05 10:33:35.770: E/AndroidRunt
我浏览过现有的帖子,这些帖子处理在 Eclipse 中的 Tomcat 下运行 Java Web 应用程序的 ClassNotFoundException。 我无法提供源代码和配置 Artifact
我忙于我的应用一个多星期,突然: 11-12 07:59:17.860 1653-1653/nl.test.myapp E/AndroidRuntime﹕ FATAL EXCEPTION: ma
我的应用程序有问题,昨天一切正常,但今天我更新了 sdk,现在当我尝试运行我的应用程序时,出现这样的错误 05-21 00:14:19.285: W/dalvikvm(7061): Unable t
我正在阅读 JPA docs在 Spring ,我正在尝试重组我的代码。 我现在所拥有的: BrewerRepository @Repository public class BrewerReposi
我想像 BalusC's example 一样实现 fileUpload . 不幸的是,我已经在努力声明 servlet。 Extensions Filter javax.faces
在某些机器上运行这个小程序不起作用,但在其他机器上它工作得很好。在所有情况下看起来都安装了 JRE 1.6.0_26。 var attributes = {codebase:'http://kas
我将跟随这个非常简单的教程(http://www.tutorialspoint.com/hadoop/hadoop_mapreduce.htm)一起学习,直到我尝试运行Java文件为止,一切运行良好。
我看到了帖子,并按照流程进行了操作。但这没有用。 ClassNotFoundException, while running example job of Hadoop 请帮助我。 创建的 mapre
我尝试在cloudera quickstart vm上为hadoop运行Mahout Kmeans示例。我在这里读link to clouudera block和这里stack overflow po
我有一个mapreduce程序,其中我使用Hcatalog从Hive表'A'中获取带有HcatInputFormat的详细信息,对其进行处理,然后使用HcatOutput格式将其写回到Hive表'B'
我是激发应用程序编程的新手,因此在这里为这个基本的编程而苦苦挣扎。 我有 scala ide 并附加了来自最新 hadoop 和 spark 发行版的相关 jar 文件。我正在使用的只有一个基本的 s
我正在尝试在本地模式下运行Spark示例,但是正在获取以下堆栈跟踪: Exception in thread "main" java.lang.NoClassDefFoundError: org/ap
我有以下代码: // Test TODO remove try { System.out.println(System.getProperties().getPrope
我有以下文件: src/my_proj/myns.clj: (ns my-proj.myns) (defrecord MyRecord [a b c]) 测试/my_proj/myns_test.c
我试图让应用程序动态加载某些类,然后调用启动方法,但问题是,由于 ClassLoader 不同,一个类无法调用另一个类的方法,但是正如我已经用 google 搜索的那样,我用父类创建了两个类加载器。这
我是一名优秀的程序员,十分优秀!