java - How do I perform Constructor-based dependency injection with Spring using annotations? -


ok, if need put primitive values in constructor, how do that?

    @autowired public custombean(string name, @qualifier("superbean") superbean superbean) {     super();     this.superbean = superbean;     this.name = name; } 

for instance here defining superbean has qualifier "superbean", i'd know how possible use annotations set name value here?

i know it's possible xml configuration, want know how annotations too:

<bean id="customxmlbean" class="org.arturas.summerfav.beans.customxmlbean">         <constructor-arg name="name" type="string" value="the big custom xml bean" />         <constructor-arg>             <bean id="superbean" class="org.arturas.summerfav.beans.superbean" />         </constructor-arg>     </bean> 

well how put in values string, int , other generic types?

here 1 way this:

@component  public class yourbean {      @autowired     public yourbean(@value("${prop1}") string arg1, @value("${prop2}") string arg2) {          // rest of code     }  }  

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -