属性注入
spring属性注入使用properties
import org.springframework.context.annotation.PropertySource; @RestController @RequestMapping(value = "/Template") @PropertySource(value = {"classpath:template.properties"}) public class MiTemplateController { @Value("${template}") private String template; @Value("${detail}") private String detail; } }
文件内容
template=[{"templatId":"1","templateName":"\u6A21\u677F1"},{"templateId":"2","templateName":"\u6A21\u677F2"},{"templateId":"3","templateName":"\u6A21\u677F3"}]spring
spring注解注入属性
1.直接注入值
@Value("/tmp/aaa.xlsx")
2.通过配置yml注入值
@Value("${detail}")