zoukankan      html  css  js  c++  java
  • 第三周作业

    1、项目中关于web集成hibernate和spring中遇到的问题

      答:(1)最容易导致空指针的地方:在servlet层调用service层中的方法。不能运用平时的@resource注入,要添加如下方法。获取到service bean    

      public void init(ServletConfig config) throws ServletException {
    ApplicationContext context=ContextLoader.getCurrentWebApplicationContext();
    userService=(IUserService)context.getBean("userService",IUserService.class);
    }

        (2)在进行添加操作时,报如下错误

            Write operations are not allowed in read-only mode 只读模式下(FlushMode.NEVER/MANUAL)写操作不允

            org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode           (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.

        解决方案:

    <filter>
    <filter-name>hibernateFilter</filter-name>
    <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class> <init-param>
    <param-name>flushMode</param-name>
    <param-value>AUTO</param-value>
    </init-param>
    <init-param>
    <param-name>singleSession</param-name>
    <param-value>false</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>hibernateFilter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>

  • 相关阅读:
    python 多线程测试
    python 多线程join()
    python 多线程 t.setDaemon(True):
    线程锁
    python 多线程
    模板渲染和参数传递.
    求两个数组的交集
    java数组并集/交集/差集(补集)
    java各种集合的线程安全
    页面跳转和重定向
  • 原文地址:https://www.cnblogs.com/linnaf5/p/5296746.html
Copyright © 2011-2022 走看看