SPRING 3.0.0.M3 ON GOOGLE APPENGINE WITH JPA (zt)

source: http://www.eisele.net/blog/2009/07/spring-300m3-on-google-appengine-with.html

 

I am working on a private project these days. It should give myfear.com and myfear.de a new meaning. Therefore I am trying out Google's Appengine.

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:


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 :)

根据引用中的错误信息,可以看出在创建名为 'departmentMapper'的bean时发生了错误。错误原因是缺少 'sqlSessionFactory' 或 'sqlSessionTemplate' 属性。这意味着在创建该bean时,需要注入一个名为 'sqlSessionFactory' 或 'sqlSessionTemplate' 的属性。根据引用的描述,可能是由于项目中引入了 common 工程导致的错误。在引用中,提到在 pom 文件中配置了 Spring Data REST HAL Browser 的依赖项。可能需要进一步检查该依赖项是否与项目的其他配置和依赖项兼容,以防止冲突。建议检查项目的配置和依赖项,确保正确配置了 'sqlSessionFactory' 或 'sqlSessionTemplate' 属性,并确保所有的依赖项都正确引入和配置。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [org.springframework.beans.factory.BeanCreationException: Error creating bean with name gradle相关](https://blog.csdn.net/AfterLife1220/article/details/129205367)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [原项目引入springcloud报错:org.springframework.boot.context.properties....](https://blog.csdn.net/qun7559/article/details/123492415)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Springboot+swagger2 compatible version of org.springframework.plugin.core.PluginRegistry](https://blog.csdn.net/qq_40437747/article/details/108137427)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值