【问题标题】:Spring mvc, hibernate, crudSpring mvc,休眠,crud
【发布时间】:2016-10-02 07:45:55
【问题描述】:

<tx:annotation-driven><tx:annotation-driven proxy-target-class="true" 之间的区别

【问题讨论】:

  • 您的字段类型应该是BookService,而不是BookServiceImpl
  • 感谢它对我有用
  • 如果我们将 更改为 ,它工作得很好。

标签: hibernate spring-mvc crud


【解决方案1】:

尝试使用接口BookService作为控制器中的字段类型。 造成这个问题的原因是 Spring 更喜欢使用 AOP 的接口,因为它可以使用 JDK 代理。

Spring AOP 使用 JDK 动态代理或 CGLIB 来创建 给定目标对象的代理。 (JDK 动态代理是首选 随时选择)。

如果要代理的目标对象至少实现一个接口 然后将使用 JDK 动态代理。所有接口 由目标类型实现的将被代理。如果目标对象 没有实现任何接口,那么将创建一个 CGLIB 代理。

更多信息请阅读this

【讨论】:

    【解决方案2】:

    添加servlet映射标签

      <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
      </servlet-mapping>
    

    新问题提出新问题更好

    【讨论】:

      【解决方案3】:

      我尝试在控制器中使用接口BookService作为字段类型,问题解决了。然后,我运行程序,没有错误。但是,我的url请求没有响应。我该如何解决是吗?

      This is problem:

      web.xml

      <?xml version="1.0" encoding="UTF-8"?>
       <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns="http://xmlns.jcp.org/xml/ns/javaee"
      xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
       http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
      id="WebApp_ID" version="3.1">
      
      <!-- The definition of the Root Spring Container shared by all Servlets 
          and Filters -->
      <context-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>/WEB-INF/spring/root-context.xml</param-value>
      </context-param>
      
      <!-- Creates the Spring Container shared by all Servlets and Filters -->
      <listener>
          <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
      
      <!-- Processes application requests -->
      <servlet>
          <servlet-name>appServlet</servlet-name>
          <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
          <init-param>
              <param-name>contextConfigLocation</param-name>
              <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
          </init-param>
          <load-on-startup>1</load-on-startup>
      </servlet>
      
      
      
      
      
      <filter>
          <filter-name>encodingFilter</filter-name>
          <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
      
          <init-param>
              <param-name>encoding</param-name>
              <param-value>UTF-8</param-value>
          </init-param>
      
          <init-param>
              <param-name>forceEncoding</param-name>
              <param-value>true</param-value>
          </init-param>``
      </filter>
      <filter-mapping>
          <filter-name>encodingFilter</filter-name>
          <url-pattern>/*</url-pattern>
      </filter-mapping>
      

      【讨论】:

      • 你应该问第二个问题,而不是使用答案空间来问它
      猜你喜欢
      • 2014-02-02
      • 1970-01-01
      • 1970-01-01
      • 2012-01-02
      • 1970-01-01
      • 2015-02-01
      • 1970-01-01
      • 2020-11-07
      • 2013-09-18
      相关资源
      最近更新 更多