在Spring配置类中是否可以构造函数注入? [英] Is constructor injection possible in Spring configuration classes?

查看:1025
本文介绍了在Spring配置类中是否可以构造函数注入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个Spring配置类(即用@Configuration注释的类),我可以使用构造函数注入吗?

If I have a Spring configuration class (i.e. a class annotated with @Configuration) can I use constructor injection ?

如果我添加一个,没有默认构造函数消息,如果我添加一个默认的构造函数,它使用而不是重载的,这不是真正的帮助。

As it stands if I add one I get a no default constructor message, and if I add a default constructor it uses that rather than the overloaded one, which doesn't really help.

推荐答案

有关此限制的错误报告。它将用Spring 4.3修复。

There is a bug report about this limitation. It will be fixed with Spring 4.3.

请注意,另一个错误报告< a>(不是固定的今天固定在4.3-RC1)报告一个问题,当使用这个非常新的功能和注入泛型在@Configuration类的构造函数。

Please note that another bug report (not fixed yet today fixed in 4.3-RC1) report a problem when using this very new feature and injecting generics in constructor of a @Configuration class.

这篇关于在Spring配置类中是否可以构造函数注入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆