qq_某某_22
2020-08-06 16:56
如果我有两个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;
}
}
已经搞定。
Spring框架小白的蜕变
35755 学习 · 117 问题
相似问题