Java 弹簧&x2B;GAE spring容器的初始化不正确
我正试图编写一个使用Spring+GAE启用的aoolication,但我遇到了一个非常奇怪的问题 对于具有以下persistence.xml文件的持久层I用户JPA:Java 弹簧&x2B;GAE spring容器的初始化不正确,java,spring,google-app-engine,google-cloud-datastore,gae-eclipse-plugin,Java,Spring,Google App Engine,Google Cloud Datastore,Gae Eclipse Plugin,我正试图编写一个使用Spring+GAE启用的aoolication,但我遇到了一个非常奇怪的问题 对于具有以下persistence.xml文件的持久层I用户JPA: <?xml version="1.0" encoding="UTF-8" ?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
<?xml version="1.0" encoding="UTF-8" ?>
<persistence 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_1_0.xsd"
version="1.0">
<persistence-unit name="transactions-optional">
<provider>org.datanucleus.store.appengine.jpa.DatastorePersistenceProvider</provider>
<properties>
<property name="datanucleus.NontransactionalRead" value="true" />
<property name="datanucleus.NontransactionalWrite" value="true" />
<property name="datanucleus.ConnectionURL" value="appengine" />
</properties>
</persistence-unit>
</persistence>
然后我查看了日志,我可以看到entityManagerFactory在DAO初始化之前成功创建了,但就在DAO对象的实际初始化开始之前,spring只是销毁了所有的单例,包括这个单例。有很多日志,但我确信entityManagerFactory也会创建,有一件事我很奇怪,那就是为什么spring会用以下日志消息销毁所有单例:
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1594a88: defining beans [org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,entityManagerFactory,transactionManager,datastoreService,memcacheServiceUser,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,userDaoJpa,employeeDS,messageSource]; root of factory hierarchy
Jan 14, 2011 11:12:12 AM org.springframework.beans.factory.support.DisposableBeanAdapter destroy
FINE: Invoking destroy() on bean with name 'entityManagerFactory'
Jan 14, 2011 11:12:12 AM org.springframework.orm.jpa.AbstractEntityManagerFactoryBean destroy
INFO: Closing JPA EntityManagerFactory for persistence unit 'transactions-optional'
Jan 14, 2011 11:12:12 AM org.springframework.web.context.ContextLoader initWebApplicationContext
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDaoJpa' defined in file
类JpaDaoSupport希望您在构造时设置
EntityManagerFactory
或JpaTemplate
。像这样的东西应该可以做到:
@Repository
public class YourDAOImpl extends JpaDaoSupport implements YourDAO
{
@Autowired
public YourDAOImpl(EntityManagerFactory entityManagerFactory)
{
setEntityManagerFactory(entityManagerFactory);
}
...
}
您可以使用以下命令自动插入实体管理器
@PersistenceContext
private EntityManager entityManager;
每个都由Dao实现。由于启动失败,单例正在被销毁。这与你的问题无关。另外,请向我们展示
IllegalArgumentException
的完整堆栈跟踪,而不仅仅是您发布的代码片段。
@Repository
public class YourDAOImpl extends JpaDaoSupport implements YourDAO
{
@Autowired
public YourDAOImpl(EntityManagerFactory entityManagerFactory)
{
setEntityManagerFactory(entityManagerFactory);
}
...
}
@PersistenceContext
private EntityManager entityManager;
@Autowired
public ClaseDaoImpl(EntityManagerFactory entityManagerFactory) {
setEntityManagerFactory(entityManagerFactory);
}