如果我有两个List,那@Bean,是给那个List写入?
如果我有两个List,那@Bean,是给那个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; } }