今天看源码发现DruidDataSource中的配置代码如下:
然后我在DruidConfig中使用的@ConfigurationProperties(prefix = "spring.datasource")注解,为什么yml配置文件中的druid配置是spring.datasource.xxx才会生效,为什么不是spring.datasource.druid.xxx
@Configuration
public class DruidConfig {
@Bean
@ConfigurationProperties(prefix = "spring.datasource")
public DruidDataSource druidDataSource(){
return new DruidDataSource();
}
@Bean
public ServletRegistrationBean<StatViewServlet> registrationBean(){
ServletRegistrationBean<StatViewServlet> servletRegistrationBean = new ServletRegistrationBean<>(new StatViewServlet(), "/druid/*");
HashMap<String, String> stringStringHashMap = new HashMap<>();
stringStringHashMap.put("loginUsername","root");
stringStringHashMap.put("loginPassword","123456");
servletRegistrationBean.setInitParameters(stringStringHashMap);
return servletRegistrationBean;
}
}