如何在不使用 @Autowire
的情况下将处理程序注入(inject)注解 Controller (@Controller
)?
最佳答案
当然,您始终可以在 XML 中配置 Autowiring :
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
default-autowire="byType">
<!-- all beans here will be autowired, including those
found by <contect:component-scan /> -->
</beans>
但是您可能必须为属性提供 Setter 方法。
顺便说一句,如果你不想的话,你也可以使用 JSR-250 @Resource
注释(当然还有 JSR-330 的 @Inject
,感谢@Bozho)使用 Spring 专有的 @Autowired
注释。
关于java - 将 Handler 注入(inject)注解 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4721031/