Beeing forced to more or less full blown JEE5 in my dayly work, I wanted to try out something new. Having worked with older Spring versions some time ago, I feelt it was time to give this another shot. And so I ended up, trying Spring's newest milestone release on the GAE.
At the end of the day, I solved many problems on the road and everything worked fine. Here is a brief summary of what I had to change/find out:
1) GAE does not support full blown JEE. Therefore you have to be very sensible for using the right combination of technologies. If you try to use spring completely you will fail. The following list of jar files did the job for me:
antlr-3.0.1.jar
aopalliance-1.0.jar
asm-2.1.jar
asm-commons-2.1.jar
commons-beanutils-1.7.0.jar
commons-collections-3.1.jar
commons-lang.jar
commons-logging.jar
org.springframework.aop-3.0.0.M3.jar
org.springframework.asm-3.0.0.M3.jar
org.springframework.aspects-3.0.0.M3.jar
org.springframework.beans-3.0.0.M3.jar
org.springframework.context-3.0.0.M3.jar
org.springframework.core-3.0.0.M3.jar
org.springframework.expression-3.0.0.M3.jar
org.springframework.jdbc-3.0.0.M3.jar
org.springframework.orm-3.0.0.M3.jar
org.springframework.transaction-3.0.0.M3.jar
org.springframework.web-3.0.0.M3.jar
org.springframework.web.servlet-3.0.0.M3.jar
2) Setting up the persistance.xml is straight forward but remember to rename the persistance-unit in jdoconfig.xml. Both should have different names!
<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>
3) Defining the entity manager in dispatcher-servlet.xml
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"
lazy-init="true">
<property name="persistenceUnitName" value="transactions-optional" />
</bean>
<bean name="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
Don't forget to add the following two, if you want to use JPA @Annotations in your Entities and Spring @Annotations in your DAOs and Services.
<tx:annotation-driven />
<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
4) Injecting the EntityManager in your @Repository Daos:
5) If you try to use the injected entityManager without any transaction, then you would most likely get an NucleusUserException: Object Manager has been closed. You can prevent this, using @Service and @Transactional in your service layer.
6)Nearly the same could happen, if you do not call queryResult.size() on your query.getResultList(). The error was reported several times. There seems to exist only this "workaround".
7) Using EL Expressions in your JSP forces you to use a little addon to the jsp page definition:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"isELIgnored="false"%>
8) If you would like to use the <fmt:formatDate jstl tags, you have to enable session management in your appengine-web.xml. <sessions-enabled>true</sessions-enabled>
9) I came across several problems using a JRE with eclipse and GAE local server. You should always use a JDK!
All for now ... more to come :)
At the end of the day, I solved many problems on the road and everything worked fine. Here is a brief summary of what I had to change/find out:
1) GAE does not support full blown JEE. Therefore you have to be very sensible for using the right combination of technologies. If you try to use spring completely you will fail. The following list of jar files did the job for me:
antlr-3.0.1.jar
aopalliance-1.0.jar
asm-2.1.jar
asm-commons-2.1.jar
commons-beanutils-1.7.0.jar
commons-collections-3.1.jar
commons-lang.jar
commons-logging.jar
org.springframework.aop-3.0.0.M3.jar
org.springframework.asm-3.0.0.M3.jar
org.springframework.aspects-3.0.0.M3.jar
org.springframework.beans-3.0.0.M3.jar
org.springframework.context-3.0.0.M3.jar
org.springframework.core-3.0.0.M3.jar
org.springframework.expression-3.0.0.M3.jar
org.springframework.jdbc-3.0.0.M3.jar
org.springframework.orm-3.0.0.M3.jar
org.springframework.transaction-3.0.0.M3.jar
org.springframework.web-3.0.0.M3.jar
org.springframework.web.servlet-3.0.0.M3.jar
2) Setting up the persistance.xml is straight forward but remember to rename the persistance-unit in jdoconfig.xml. Both should have different names!
<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>
3) Defining the entity manager in dispatcher-servlet.xml
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"
lazy-init="true">
<property name="persistenceUnitName" value="transactions-optional" />
</bean>
<bean name="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
Don't forget to add the following two, if you want to use JPA @Annotations in your Entities and Spring @Annotations in your DAOs and Services.
<tx:annotation-driven />
<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
4) Injecting the EntityManager in your @Repository Daos:
private EntityManager entityManager;
@PersistenceContext
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}
5) If you try to use the injected entityManager without any transaction, then you would most likely get an NucleusUserException: Object Manager has been closed. You can prevent this, using @Service and @Transactional in your service layer.
6)Nearly the same could happen, if you do not call queryResult.size() on your query.getResultList(). The error was reported several times. There seems to exist only this "workaround".
7) Using EL Expressions in your JSP forces you to use a little addon to the jsp page definition:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"isELIgnored="false"%>
8) If you would like to use the <fmt:formatDate jstl tags, you have to enable session management in your appengine-web.xml. <sessions-enabled>true</sessions-enabled>
9) I came across several problems using a JRE with eclipse and GAE local server. You should always use a JDK!
All for now ... more to come :)
相关推荐
spring3.0.0相关jar包 org.springframework.aop-3.0.0.RELEASE org.springframework.asm-3.0.0.RELEASE org.springframework.aspects-3.0.0.RELEASE org.springframework.beans-3.0.0.RELEASE org.springframework....
org.springframework.aop-3.0.0.M3.jar
org.springframework.beans-3.0.0.M3.jar
org.springframework.core-3.0.0.M3.jar
org.springframework.test-3.0.0.M3.jar 包
aopalliance-1.0.jar,org.springframework.aop-3.0.0.RELEASE.jar,org.springframework.jdbc-3.0.0.RELEASEorg.springframework.beans-3.0.0.RELEASE.jar等
org.springframework.instrument-3.0.0.M3.jar
org.springframework.aspects-3.0.0.M3.jar
org.springframework.expression-3.0.0.M3.jar
org.springframework.context-3.0.0.M3.jar
org.springframework.asm-3.0.0.M3.jar
org.springframework.context.support-3.0.0.M3.jar
赠送jar包:javax.servlet-3.0.0.v201112011016.jar; 赠送原API文档:javax.servlet-3.0.0.v201112011016-javadoc.jar; 赠送源代码:javax.servlet-3.0.0.v201112011016-sources.jar; 赠送Maven依赖信息文件:...
org.springframework.transaction-3.0.0.M4.jar: 为JDBC、Hibernate、JDO、JPA等提供的一致的声明式和编程式事务管理 org.springframework.web.servlet-3.0.0.M4.jar: SpringMVC org.springframework.jms-3.0.0.M4...
赠送jar包:javax.servlet-3.0.0.v201112011016.jar; 赠送原API文档:javax.servlet-3.0.0.v201112011016-javadoc.jar; 赠送源代码:javax.servlet-3.0.0.v201112011016-sources.jar; 赠送Maven依赖信息文件:...
《Spring Web框架详解——基于org.springframework.web-3.0.0.RC3.jar》 Spring Web框架是Java Web开发中的重要组成部分,它为构建高效、灵活的Web应用程序提供了强大支持。在本文中,我们将深入探讨Spring Web框架...
在这个场景中,我们关注的是Redis的集群搭建,涉及到的文件是"redis-3.0.0.tar"和"redis-3.0.0.gem"。这两个文件分别对应Redis服务本身和通过Ruby来创建Redis集群的工具。 首先,`redis-3.0.0.tar`是一个源代码...
《Spring 框架 3.0.0.M2:深度探索与应用实践》 Spring 框架作为 Java 开发领域中的一个基石,自诞生以来就以其强大的功能和灵活性赢得了广大开发者的青睐。3.0.0.M2 版本是 Spring 的一个重要里程碑,它在原有基础...
《Spring框架3.0.0.RC3深度解析》 Spring框架是Java开发中的核心组件,尤其在企业级应用开发中扮演着至关重要的角色。3.0.0.RC3版本是Spring发展的一个重要里程碑,引入了许多创新特性和优化,为开发者提供了更强大...
在数据访问层,Spring 3.0.0.RC3增强了对JPA(Java Persistence API)和Hibernate的支持,提供了一致的编程模型和声明式事务管理。`@Transactional`注解使得事务管理变得简单,开发者可以在方法级别控制事务的边界。...