我使用自己的验证器类,并在控制器中使用 @Autowired -annotation 对其进行标记。我还必须使用数据库和 LDAP 连接,因此我也在同一个控制器构造函数中自动装配它们。
我的验证器也必须使用数据库和 ldap 连接,因此我必须在其构造函数中自动装配数据库和 ldap。确实是双重自动装配!但现在我的问题是如何让数据库和 ldap 在验证器中工作?如果没有接线,它们将返回 null。有什么帮助吗?
这是我之前关于自动装配的问题的延续。
I use my own validator class and mark it with @Autowired -anotation in my controller. I also have to use database and ldap connections, so I autowire them too in the same controller constructor.
My validator must use database and ldap connections too, so I'd have to autowire database and ldap in its constructor. It is double autowiring indeed! But now my problem is how can I get the database and ldap work in validator? With no wiring, they return null. Any help?
This is a continuence to my earlier question about autowiring.
发布评论
评论(3)
我在这里没有看到真正的问题。阅读 Spring 参考的以下部分:
@Autowired
和@Inject
I don't see a real question in here. Read these parts of the Spring Reference:
@Autowired
and@Inject
自动接线实际上是否按照您期望的方式进行?或者,您可以明确地注入您的依赖项以确保安全。
Are the autowires actually doing what you expect them to do? Alternatively you can explicitely inject your dependencies to be sure.
控制器中的@Autowire将验证器连接到控制器。您还需要在验证器中添加@Autowire以连接ldap和数据库bean。还请在您的问题中添加您的代码和配置,以便我们更好地理解它。
The @Autowire in the Controller is wiring validator to the controller.You need to add @Autowire in Validator as well to wire ldap and database beans. Please also add your code and configuration in your question so that we can understand it better.