1.使用@Component和@Value()注解读取属性

1.1 创建一个Role类,如图
springboot读取属性

1.2在全局配置文件中注入属性值
springboot读取属性

1.3调用role
springboot读取属性

1.4浏览器访问
springboot读取属性

-------------敲黑板,划重点--------------

2.一般使用@Configuration和@Value和@Bean注解读取属性

2.1以上面的为例子,假设我们现在需要连接Redis
springboot读取属性

2.2在上一个例子的Role类中,如图
springboot读取属性

这样就可以实现属性的传递.

(个人学习总结,转载请注明出处,如有错误请指出,谢谢!)

相关文章: