0

如何使用 and 执行 Spring 注入<context:component-scan base-package="x.y.z.controller" /> <mvc:annotation-driven/>?

当我们使用<mvc:annotation-driven/>then 我们不必为控制器指定我们的 bean,所以当我们使用<context:component-scan base-package="x.y.z.controller" />.

4

2 回答 2

1

利用

@Autowire注释并在 Application context.xml 中定义 <\bean>

是一个例子。看一看

于 2013-08-28T05:49:03.450 回答
0

您可以使用 JSR 330 注释:@Inject. 您也可以使用 Spring 特定的@Autowired,但@Inject更好,因为基于标准参考。有关更多信息,请参阅Spring 文档

来自 Spring 文档的示例:

@Inject
public void setMovieFinder(MovieFinder movieFinder) {
    this.movieFinder = movieFinder;
}
于 2013-08-28T06:14:42.323 回答