0

我正在使用 JSF 2.0 和 Primefaces 3.4.2.、Spring 3.1.1 和 Hibernate 4.0.1

我混合使用了 CODI@ViewAccessScoped和 Spring ManagedBeans,因此我在会话方面遇到了一些问题,详情请点击此处

我想删除 Spring ManagedBeans 并将 CODI@ViewAccessScoped用于我的小型应用程序。

为了仅使用 CODI,我必须采取哪些步骤@ViewAccessScoped?我只需要删除基于 Spring 的 ManagedBeans。

任何帮助都是非常可观的。

应用程序上下文.xml

<bean id="DataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/myDS"/>   
</bean>
<context:component-scan base-package="net.cstl" />
    <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>

<!-- JPA Entity Manager Factory -->
    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="DataSource" />
        <property name="packagesToScan" value="net.cstl.entity" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="false" />
                <property name="generateDdl" value="false" />
                <property name="databasePlatform" value="${jdbc.dialectClass}" />
            </bean>
        </property>
    </bean>

    <bean id="defaultLobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler" />  
     <bean id="SessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="DataSource" />
        <property name="annotatedClasses">
            <list>
                <value>net.cstl.entity.Employee</value>
                <value>net.cstl.entity.Department</value>                       
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
                <prop key="hibernate.show_sql">false</prop>
                <prop key="hibernate.query.factory_class">org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory
                </prop>
            </props>
        </property>
    </bean>

           <!-- Transaction Config -->
       <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager"/>          

     <context:annotation-config/>


    <bean id="hibernateStatisticsMBean" class="org.hibernate.jmx.StatisticsService">
        <property name="statisticsEnabled" value="true" />
        <property name="sessionFactory" value="#{entityManagerFactory.sessionFactory}" />
    </bean>
    <bean name="ehCacheManagerMBean"
        class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" />

    <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
        <property name="locateExistingServerIfPossible" value="true" />
    </bean>

    <bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false">
        <property name="server" ref="mbeanServer" />
        <property name="registrationBehaviorName" value="REGISTRATION_REPLACE_EXISTING"/>
        <property name="beans">
            <map>               
                <entry key="SpringBeans:name=hibernateStatisticsMBean" value-ref="hibernateStatisticsMBean" />
                <entry key="SpringBeans:name=ehCacheManagerMBean" value-ref="ehCacheManagerMBean" />
            </map>
        </property>
    </bean>

</beans>

面孔-config.xml

<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>

web.xml

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml </param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

托管豆

@Named("myMB")
@ViewAccessScoped
public class EmployeeController implements Serializable {

@Inject
EmployeeService employeeService;

EmployeeServiceImpl

 @Transactional
 @Service(value = "employeeService")
 public class EmployeeServiceImpl implements EmployeeService {

 @Inject
 EmployeeDAO employeeDAO;

EmployeeDAOImpl

@Repository("employeeDAO")
public class EmployeeDAOImpl extends GenericDAOImpl<Employee> implements EmployeeDAO {

@PersistenceContext
public void setEntityManager(EntityManager entityManager) {
    this.entityManager = entityManager;
    }
4

0 回答 0