application-list.properties
map.tool.cmt=fehuang2
map.tool.cmc=jieb
map.tool.slim=chzhang
map.tool.gfc=leich3
map.itl.Jack=jackc2
map.itl.Iris=yili8
map.itl.Panda=pandax
map.itl.Adun=gengwang
map.itl.Caedmon=chuankwa
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
@Component
@PropertySource(value = "classpath:application-list.properties")
@ConfigurationProperties(prefix = "map")
public class RelatedPerson {
private Map<String, String> tool = new HashMap<>();
private Map<String, String> itl = new HashMap<>();
public Map<String, String> getTool() {
return tool;
}
public void setTool(Map<String, String> tool) {
this.tool = tool;
}
public Map<String, String> getItl() {
return itl;
}
public void setItl(Map<String, String> itl) {
this.itl = itl;
}
}
- 在其他类中可以通过
@Autowired
注入的方式使用
@Service
@Transactional
public class SparkBotService {
private static final Logger logger = LoggerFactory.getLogger(SparkBotService.class);
@Autowired
private RelatedPerson relatedPerson;
private static Map<String, String> map = new HashMap<>();
@PostConstruct
public void init() {
map.putAll(relatedPerson.getItl());
map.putAll(relatedPerson.getTool());
}
}