<tfoot id='nUHlN'></tfoot>

  1. <legend id='nUHlN'><style id='nUHlN'><dir id='nUHlN'><q id='nUHlN'></q></dir></style></legend>
      <bdo id='nUHlN'></bdo><ul id='nUHlN'></ul>
  2. <i id='nUHlN'><tr id='nUHlN'><dt id='nUHlN'><q id='nUHlN'><span id='nUHlN'><b id='nUHlN'><form id='nUHlN'><ins id='nUHlN'></ins><ul id='nUHlN'></ul><sub id='nUHlN'></sub></form><legend id='nUHlN'></legend><bdo id='nUHlN'><pre id='nUHlN'><center id='nUHlN'></center></pre></bdo></b><th id='nUHlN'></th></span></q></dt></tr></i><div id='nUHlN'><tfoot id='nUHlN'></tfoot><dl id='nUHlN'><fieldset id='nUHlN'></fieldset></dl></div>

      <small id='nUHlN'></small><noframes id='nUHlN'>

    1. Spring:具有基于注释的配置的原始值(属性)的构造

      时间:2023-09-27
          • <bdo id='nBLir'></bdo><ul id='nBLir'></ul>

                <tbody id='nBLir'></tbody>

              <small id='nBLir'></small><noframes id='nBLir'>

              <legend id='nBLir'><style id='nBLir'><dir id='nBLir'><q id='nBLir'></q></dir></style></legend>
                <i id='nBLir'><tr id='nBLir'><dt id='nBLir'><q id='nBLir'><span id='nBLir'><b id='nBLir'><form id='nBLir'><ins id='nBLir'></ins><ul id='nBLir'></ul><sub id='nBLir'></sub></form><legend id='nBLir'></legend><bdo id='nBLir'><pre id='nBLir'><center id='nBLir'></center></pre></bdo></b><th id='nBLir'></th></span></q></dt></tr></i><div id='nBLir'><tfoot id='nBLir'></tfoot><dl id='nBLir'><fieldset id='nBLir'></fieldset></dl></div>

                <tfoot id='nBLir'></tfoot>
                本文介绍了Spring:具有基于注释的配置的原始值(属性)的构造函数注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在尝试在 Spring 3 中使用基于注释的配置来配置一个类,它将原始值作为其构造函数参数:

                I'm trying to configure a class with Annotation based configuration in Spring 3, which takes primitive values as its constructor arguments:

                @Component
                class MyBean {
                  MyBean(String arg1, String arg2) {
                    // ...
                  }
                }
                

                还有这样的应用程序上下文:

                And an application context like this:

                <beans [...]>
                  <context:component-scan base-package="com.example" />
                  <context:property-override location="/WEB-INF/example.properties" />
                </beans>
                

                我正在尝试找到某种方法来指定构造函数参数应取自属性文件.显然,这确实适用于采用常规 bean 的构造函数(例如 MyClass(Bean bean1, OtherBean bean2)),但只是属性?

                I'm trying to find some way to specify that the constructor arguments should be taken from the properties file. Apparently this does work with constructors that take regular beans (e.g. MyClass(Bean bean1, OtherBean bean2)), but just properties?

                我还尝试使用 Spring 3 的 @Value 注释和值的 EL 表达式来注释构造函数参数,例如 @Value("#{prop.Prop1}") arg1,但这似乎也不起作用.

                I have also tried annotating the constructor arguments with Spring 3's @Value annotation and an EL expression for the value, like @Value("#{prop.Prop1}") arg1, but that doesn't seem to work either.

                推荐答案

                以下代码在 <context:property-placeholder .../> 下运行良好:

                The following code works fine with <context:property-placeholder .../>:

                @Component 
                public class MyBean { 
                    @Autowired
                    public MyBean(@Value("${prop1}") String arg1, @Value("${prop2}") String arg2) { 
                        // ... 
                    } 
                } 
                

                但是<context:property-override .../>是很具体的东西,这里不适合.

                But <context:property-override .../> is a very specific thing, it's not suitable here.

                这篇关于Spring:具有基于注释的配置的原始值(属性)的构造函数注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Java Annotations - 寻找 RetentionPolicy.CLASS 的示例 下一篇:java.lang.IllegalStateException:Bean 名称“类别"的

                相关文章

                最新文章

                <legend id='RTQwv'><style id='RTQwv'><dir id='RTQwv'><q id='RTQwv'></q></dir></style></legend>

                  <tfoot id='RTQwv'></tfoot>

                1. <i id='RTQwv'><tr id='RTQwv'><dt id='RTQwv'><q id='RTQwv'><span id='RTQwv'><b id='RTQwv'><form id='RTQwv'><ins id='RTQwv'></ins><ul id='RTQwv'></ul><sub id='RTQwv'></sub></form><legend id='RTQwv'></legend><bdo id='RTQwv'><pre id='RTQwv'><center id='RTQwv'></center></pre></bdo></b><th id='RTQwv'></th></span></q></dt></tr></i><div id='RTQwv'><tfoot id='RTQwv'></tfoot><dl id='RTQwv'><fieldset id='RTQwv'></fieldset></dl></div>

                  <small id='RTQwv'></small><noframes id='RTQwv'>

                    • <bdo id='RTQwv'></bdo><ul id='RTQwv'></ul>