基于SSH框架实际开发时遇到的问题及解决办法

1. 发现通过注解注入bean不起作用(对应的.java文件上没有'S'标记)

  需要在pring .xml配置文件中加

<!-- 使用自动注解就必须配置加入自动扫描加载容器的包 -->
    <context:component-scan base-package="com.*"></context:component-scan>

 

2. getSession时 sessionFactory.getCurrentSession()获取不到session,原因是没有配置事务绑定线程,在spring .xml中配置事务即可。

<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactoryBean"></property>
    </bean>
    <tx:advice id="advice" transaction-manager="transactionManager">
        <tx:attributes>
            <!-- 执行事务的方法名 -->
            <tx:method name="*"/>
        </tx:attributes>
    </tx:advice>
    <aop:config>
        <!-- 配置切点  -->
        <aop:pointcut expression="execution(* com.blog.service.*.*(..))" id="pointcut"/>
        <aop:advisor advice-ref="advice" pointcut-ref="pointcut"/>
    </aop:config>

 

posted @ 2016-04-01 15:09  Scoee  阅读(1171)  评论(0编辑  收藏  举报