2

我正在编写使用Spring MVC将 Spring bean 与类似 REST 的通道绑定的 Web 应用程序。

<mvc:annotation-driven/>我已经在我以前的应用程序(纯 XML 配置)和使用功能的示例中创建了基本配置。我<context:component-scan base-package="my.package"/>在 spring xml 文件中指向一个带有控制器的包。

它在Spring 3.0.6.RELEASE中工作。但是,升级到3.1.0.RELEASE后,我的控制器停止检测,并且没有注册任何频道。Spring 上下文不包含HelloChannel接口的实现。

这是这个 Spring 版本中的错误,还是我正在使用已弃用的配置,在较新版本中不再支持?我没有收到错误或警告,只是没有自动检测到 bean。

控制器接口定义如下所示:

@RequestMapping("/config") public interface ConfigChannel

和实施:

@Controller
public class ConfigChannelImpl implements ConfigChannel
4

1 回答 1

2

Spring 文档表明基于接口的@Controllers 用于代理事务方法。因此,您可能正在使用该<tx:annotation-driven />标签。您现在似乎遇到的问题是 Spring 3.1 引入了对 CGLIB 的支持,CGLIB 是一个基于运行时的字节码操纵器。您需要添加proxy-target-class="true"到您的事务配置并将 CGLIB 添加到您的类路径中。

<tx:annotation-driven proxy-target-class="true" />

来自http://static.springsource.org/spring/docs/3.1.0.M1/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping

于 2011-12-29T14:29:48.853 回答