application.properties內(nèi)容:
neo.title=純潔的微笑
neo.description=分享技術(shù)赋访,品味生活
redis.port = 3306
redis.ip = 127.0.0.1
普通注入值
@Value("${neo.title}")
private String title;
自定義配置文件
redis.properties
redis.ip=127.0.0.1
redis.port=3306
創(chuàng)建實(shí)體類
@Getter @Setter
@Component
@ConfigurationProperties(prefix="redis")
@PropertySource("classpath:redis.properties")
public class RedisProperties {
private String ip;
private String port;
}
@Resource
private RedisProperties properties;
如上,@PropertySource注解指定properties文件
@ConfigurationProperties指定文件中參數(shù)的前綴
@Resource為properties作注入