1 简单属性值注入package com.xy.test1;import org.springframework.beans.factory.annotation.Value;import org.springframework.stere
1 简单属性值注入
package com.xy.test1;import org.springframework.beans.factory.annotation.Value;import org.springframework.stereotype.Service;@Service // 需要被注入属性值的类需要被Spring管理 public class PropertiesService1 {// 利用@Value注解,即使没有该属性或者属性文件也不会报错 // @Value输入属性值name,默认值xydefault @Value("${name:xydefault}") private String name;// @Value输入属性值num,默认值-1 @Value("${num:-1}") private Integer num;// @Value输入属性值type,默认值-2 @Value("${type:-2}") private Integer type;public void getInfo() {System.out.println("name:" + name + ",num:" + num + ",type:" + type);}}
--结束END--
本文标题: Spring中利用配置文件和@value注入属性值代码详解
本文链接: https://www.lsjlt.com/news/221339.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-10
2024-05-10
2024-05-10
2024-05-10
2024-05-10
2024-05-10
2024-05-10
2024-05-10
2024-05-10
2024-05-10
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0