【spring-boot】Failed to bind properties under 'spring.datasource' to javax.sql.DataSource:

Errors encountered when integrating Druid

When integration springboot druid, druid data source is introduced, disposed in the configuration of the configuration file application.yml

initialSize: 5 
minIdle: 5 
maxActive: 20 
maxWait: 60000 
timeBetweenEvictionRunsMillis: 60000 
minEvictableIdleTimeMillis: 300000 
validationQuery: the SELECT 1 the FROM DUAL 
testWhileIdle: to true 
testOnBorrow: false 
testOnReturn: false 
poolPreparedStatements: to true 
# configure the monitoring statistics intercepted filters, after removing the monitoring interface sql not statistics, 'wall' firewalls 
Filters: STAT, Wall, log4j 
maxPoolPreparedStatementPerConnectionSize: 20 is 
useGlobalDataSourceStat: to true 
ConnectionProperties: = druid.stat.mergeSql to true; druid.stat.slowSqlMillis = 500

 


Also made configuration DruidConfig.class

. 1  @Configuration
 2  public  class DruidConfig {
 . 3  
. 4 @ConfigurationProperties (prefix = "spring.datasource" )
 . 5  @Bean
 . 6  public the DataSource Druid () {
 . 7  return  new new DruidDataSource ();
 . 8  }
 . 9  
10  // configuration monitoring Druid
 11  / / 1, a configuration management background of the Servlet 
12 is  @Bean
 13 is  public ServletRegistrationBean statViewServlet () {
 14 ServletRegistrationBean the bean = new new ServletRegistrationBean ( new new StatViewServlet(), "/druid/*");
15 Map<String, String> initParams = new HashMap<>();
16 
17 initParams.put("loginUsername", "admin");
18 initParams.put("loginPassword", "123456");
19 initParams.put("allow", "");// 默认就是允许所有访问
20 initParams.put("deny", "10.18.172.124");
21 
22 bean.setInitParameters(initParams);
23 return bean;
public28@Bean
272, arranged to monitor a web filter//26 is25}
24  
 
   FilterRegistrationBean webStatFilter() {
29 FilterRegistrationBean bean = new FilterRegistrationBean();
30 bean.setFilter(new WebStatFilter());
31 
32 Map<String, String> initParams = new HashMap<>();
33 initParams.put("exclusions", "*.js,*.css,/druid/*");
34 
35 bean.setInitParameters(initParams);
36 
37 bean.setUrlPatterns(Arrays.asList("/*"));
38 
39 return bean;
40 }
41 }
View Code

 


But when you start being given:

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to bind properties under 'spring.datasource' to javax.sql.DataSource:

    Property: spring.datasource.filters
    Value: stat,wall,log4j
    Origin: class path resource [application.yml]:24:14
    Reason: org.apache.log4j.Logger

Action:

Update your application's configuration

 

 

According to the line 24 error prompt in the configuration file, view the configuration file, the line of code that filters: stat, wall, log4j

See given reason Reason: org.apache.log4j.Logger, then I guess less dependent log4j related to the introduction of dependencies in the pom

1 <!-- https://mvnrepository.com/artifact/log4j/log4j -->
2 <dependency>
3 <groupId>log4j</groupId>
4 <artifactId>log4j</artifactId>
5 <version>1.2.17</version>
6 </dependency>
View Code

 


Started again, success!
[Reserved] ----> Original

Guess you like

Origin www.cnblogs.com/jums/p/11300947.html