zoukankan      html  css  js  c++  java
  • S2S4H整合注意问题

    整合过程中出现问题记录:

    1、The import javax.servlet.http.HttpServletRequest cannot be resolved

      解决办法:在tomcat的lib目录下找到 servlet-api.jar 加载classpath下面

    2、Bean named '*' must be of type [*], but was actually of type [$Proxy16]

      原来在定义Dao时,没有用接口,而直接使用的是Dao的实现类就会导致这种错误

    3、整合中每一个action默认都是单例模式所以在action中必须加上@scope("prototype"),

      否则这个action中数据就会被所有用户所有线程共享

    4、springAOP的使用 引入aopalliance-1.0.jar 自己写一个类实现MethodInterceptor 重写 invoke方法

     1 @SuppressWarnings("serial")
     2 public class MyLoginInterceptor implements MethodInterceptor {
     3 
     4     @Override
     5     public Object invoke(MethodInvocation invoke) throws Throwable {
     6         String methodname = invoke.getMethod().getName();
     7         System.out.println(methodname);
     8         return invoke.proceed();
     9     }
    10 
    11 }

    在applicationContext.xml中配置

    1 <bean id="springMethodInterceptor" class="com.interceptor.MyLoginInterceptor" ></bean>
    2 <aop:config>
    3 //切入点
    4   <aop:pointcut id="loginPoint" expression="execution(public * com.action.*.*(..)) "/> 
    5   在该切入点使用自定义拦截器
    6   <aop:advisor pointcut-ref="loginPoint" advice-ref="springMethodInterceptor"/>
    7 </aop:config> 

    即可实现拦截com.action.*.*下面任何方法

    5、通常在使用struts2的时候使用spring的aop代理会使struts2无法获取到上下文信息,从而使参数传送失败,解决这个问题的办法就是在配置aop的时候加上 proxy-target-class="true" 即:

    <aop:config proxy-target-class="true">
    <aop:pointcut id="loginPoint" expression="execution(public * com.action.*.*(..)) "/> 
    <aop:advisor pointcut-ref="loginPoint" advice-ref="springMethodInterceptor"/>
    </aop:config>

    就ok了!!!

     6、在@manytoone设置了fetch为lazy后出现了 com.entity.User_$$_javassist_0 cannot be cast to javassist.util.proxy.Proxy异常 百度了一下

      发现是 javassit 包冲突 去除javassist-3.11.0-GA.jar包即可

     7、在一对多双向级联时 我想删除一方 在级联删除多方(通常会报 外键关联不能删除的错误) (比如删除一个帖子的同时将这个帖子的所有评论也删除)解决方法:

      先将这个帖子load出来 ,在进行删除该帖子

        @Override
        @Transactional(propagation=Propagation.REQUIRED)
        public void deletePost(Post post) {
            Post p = this.ht.get(Post.class, post.getPostid());
            this.ht.delete(p);
        }    

     8、 org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.entity.User#7826ed76-7ca8-4f44-86fe-bc0ab6e6e984]

        user - post 查询user时 会将user表中 postid 取出到 post中查询 发现post中没有 该记录 出错

  • 相关阅读:
    不知如何摧毁Kendo UI for jQuery小部件?这份指南不得不看
    MyEclipse导航代码第二弹,Java开发更便捷
    索引扫描与索引查找区别
    Chrome使用技巧
    什么是中台?所有的中台都是业务中台
    跨域资源共享CORS详解
    多线程之入门起步(三)
    聊天程序——基于Socket、Thread (二)
    多线程的相关概念(一)
    使用BCP实用工具导出导入数据
  • 原文地址:https://www.cnblogs.com/Wen-yu-jing/p/4100122.html
Copyright © 2011-2022 走看看