【发布时间】:2012-11-08 06:03:55
【问题描述】:
在 Spring MVC 中从 Controller 访问服务层的最佳方法是什么?我正在为 SpringMVC 使用注释。
之前我每次都通过在控制器的每个方法中调用 ClassPathXMLApplicationContext(spring-bean-name.xml) 从 bean factory 获取 bean。
从问题的解决方案Accessing Service Layer from custom Controller in Spring MVC 我知道服务 bean 必须是自动装配的。
但是,假设一个控制器访问多个服务,我们是否必须注入多个 bean?但这不是一个好的做法,因为我们只能在控制器中的 1-2 种方法中使用特定服务,并且将其作为类变量而不是函数变量是不好的。
【问题讨论】:
标签: java spring spring-mvc dependency-injection