我用SSH框架做电子宠物网站的时候在LoginAction类里实例化了一次BeanFactoryprivate BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("com/lovo/spring/xml/spring.xml"));
在后面的PetService里又实例化了一次private BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("com/lovo/spring/xml/spring.xml"));此时在访问时就死循环,初始化不了
如果把PetService中换成BeanFactory就可以,用上下文就不行,这是为什么

解决方案 »

  1.   

    也就是说用上下文容器就出错,用BeanFactory就没事,但是上下文才支持代理, 求助啊!!!
      

  2.   

    这是我的spring配置文件
    <beans>
    <bean id="PetService" class="com.lovo.spring.service.PetService"></bean>

    <!-- 宠物DAO实现类 -->
    <bean id="PetDAO" class="com.lovo.hibernate.dao.PetDAO">
    <!-- 将sessionFactory注入到原始DAO类中 -->
    <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>

    <!-- 日志DAO实现类 -->
    <bean id="DiaryDAO" class="com.lovo.hibernate.dao.DiaryDAO">
    <!-- 将sessionFactory注入到原始DAO类中 -->
    <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>

    <!-- 宠物手动代理类 -->
    <bean id="petDAOProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="target" ref="PetDAO"></property>
    <property name="transactionAttributes">
    <props>
    <prop key="insert*">PROPAGATION_REQUIRED</prop>
    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="update*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    <!-- 将事务管理器注入到代理类中 -->
    <property name="transactionManager" ref="transactionManager"></property>
    </bean>

    <!-- 日志手动代理类 -->
    <bean id="diaryDAOProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="target" ref="DiaryDAO"></property>
    <property name="transactionAttributes">
    <props>
    <prop key="insert*">PROPAGATION_REQUIRED</prop>
    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="update*">PROPAGATION_REQUIRED</prop>
    <prop key="delete*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    <!-- 将事务管理器注入到代理类中 -->
    <property name="transactionManager" ref="transactionManager"></property>
    </bean>

    <!-- 事务管理器 -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <!-- 将sessionFactory注入到事务管理器 -->
    <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>

    <!-- sessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <!-- <property name="configLocation">
    <value>classpath:com/lovo/orm/cfg/hibernate.cfg.xml</value>
    </property> -->
    <property name="dataSource" ref="dataSource"></property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.format_sql">true</prop>
    </props>
    </property>
    <property name="mappingDirectoryLocations">
    <list>
    <value>classpath:orm</value>
    </list>
    </property>
    </bean>

    <!-- 配置数据源(数据连接池) -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName">
    <value>com.mysql.jdbc.Driver</value>
    </property>
    <property name="url">
    <value>jdbc:mysql://localhost:3306/epet?setUnicode=true&amp;characterEncoding=utf8</value>
    </property>
    <property name="username">
    <value>root</value>
    </property>
    <property name="password">
    <value>111111</value>
    </property>
    </bean>

    </beans>