如果我有兩個(gè)List,那@Bean,是給那個(gè)List寫入?
如果我有兩個(gè)List,那@Bean,是給那個(gè)List寫入?
private?List<String>?stringList; private?List<Integer>?intList; public?List<String>?getStringList()?{ ????return?stringList; } @Autowired public?void?setStringList(List<String>?stringList)?{ ????this.stringList?=?stringList; } public?List<Integer>?getIntList()?{ ????return?intList; } @Autowired public?void?setIntList(List<Integer>?intList)?{ ????this.intList?=?intList; }
package?com.spring.ioc.demo421; import?org.springframework.context.annotation.Bean; import?org.springframework.context.annotation.ComponentScan; import?org.springframework.context.annotation.Configuration; import?java.util.ArrayList; import?java.util.List; @Configuration @ComponentScan(value?=?"com.spring.ioc.demo421") public?class?Config?{ ????@Bean ????public?List<String>?stringListed()?{ ????????List<String>?list?=?new?ArrayList<String>(); ????????list.add("jack"); ????????list.add("rose"); ????????return?list; ????} }
2020-08-06
已經(jīng)搞定。