整合ssh遇到问题

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [resource/applicationContext.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0': Cannot resolve reference to bean 'pointcut' while setting bean property 'pointcut'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pointcut': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException

 

解决方法:添加aspectjweaver.jar包

              这是Spring AOP所要用到的包

 

 

could not initialize proxy - no Session

由于在Hibernate初始化DAO和BIZ层得时候,事务由的结束是在BIZ里,此时Session已经关闭,如果我们通过jsp页面调用Session加载的某个类时,往往会引起上述错误,员工和部门是多对一的关系,在employee.hbm.xml文件中

<!-- 映射单向 n-1 的关联关系 -->
<many-to-one name="department" class="com.atguigu.ssh.entities.Department"  lazy="false">
<column name="DEPARTMENT_ID" />
</many-to-one>

令lazy="false"  这种方式不推荐使用,

 

这种方法是在网上找到的,使用时要对应自己Hibernate的版本

<!-- 当hibernate+spring配合使用的时候,如果设置了lazy=true,那么在读取数据的时候,当读取了父数据后, hibernate会自动关闭session,这样,当要使用子数据的时候,系统会抛出lazyinit的错误,
这时就需要使用spring提供的 OpenSessionInViewFilter,OpenSessionInViewFilter主要是保持Session状态
知道request将全部页面发送到客户端,这样就可以解决延迟加载带来的问题 -->
<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>*.do,*.action</url-pattern>
</filter-mapping>

posted @ 2016-06-12 16:35  hellolcc  阅读(249)  评论(0编辑  收藏  举报