spring 和struts1与jpa集成
applicationContext.xml <bean id="entiryManagerFactory" value="persistenceUnit"></property> </bean> <!-- 使用注解spring事务 --> <tx:annotation-driven transaction-manager="transactionManager"/> <!--服务层实现类--> <bean name="userService" scope="prototype"></bean> <!--在UserServiceImpl类中得到EntityManager--> @PersisterceContext private EntityManager entityManager; //可以调用entityManager.persist(obj)方法了 struts.xml <struts-config><action path="/user/add" validata="false"><forward name="list" path="/WEB-INF/page/list.jsp"></forward></action><controller><set-perperty property="processorClass" class="org.springframework.web.struts.DelegatingRequestProcessor"></controller> </struts-config> web.xml <!--实例化spring容器--> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:context/spring*.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!--spring 编码格式--> <filter> <filter-name>springCharsetEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> </filter> <!--spring解决jpa中的EntiryManage 关闭导致的延迟加载问题, 请求数据来是session打开,使用数据后session关闭--> <filter> <filter-name>entityManagerInView</filter-name> <filter-class>org.springframework.orm.jpa.support.OpenEntiryManagerInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>openSessionInView</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>entityManagerInView</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> UserAction.java //注入 spring管理 @Resource private UserService userService; 就可以调用 userService的方法了?