java.lang.NullPointerException: null at com.alibaba.druid.wall.WallFilter.init(WallFilter.java:132) ~[druid-1.2.6.jar:1.2.6] at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:830) ~[druid-1.2.6.jar:1.2.6] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_251] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_251] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_251] at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_251] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1925) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1867) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1795) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1307) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:886) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:790) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:540) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1341) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1181) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1307) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1514) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1409) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeanByName(AbstractAutowireCapableBeanFactory.java:453) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:527) ~[spring-context-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:497) ~[spring-context-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:650) ~[spring-context-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:228) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessProperties(CommonAnnotationBeanPostProcessor.java:318) ~[spring-context-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1425) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) [spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) [spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) [spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) [spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) [spring-context-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) [spring-context-5.2.14.RELEASE.jar:5.2.14.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) [spring-boot-2.3.10.RELEASE.jar:2.3.10.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:755) [spring-boot-2.3.10.RELEASE.jar:2.3.10.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.3.10.RELEASE.jar:2.3.10.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:402) [spring-boot-2.3.10.RELEASE.jar:2.3.10.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) [spring-boot-2.3.10.RELEASE.jar:2.3.10.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1247) [spring-boot-2.3.10.RELEASE.jar:2.3.10.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1236) [spring-boot-2.3.10.RELEASE.jar:2.3.10.RELEASE]yml
datasource: driver-class-name: com.p6spy.engine.spy.P6SpyDriver url: jdbc:p6spy:mysql://127.0.0.1:3306/xxxxx?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&autoReconnect=true&serverTimezone=GMT%2B8 username: root password: xxxxx type: com.alibaba.druid.pool.DruidDataSource druid: # 下面爲鏈接池的補充設置,應用到上面全部數據源中 # 初始化鏈接數大小,最小,最大 initial-size: 5 min-idle: 5 max-active: 20 # 配置獲取鏈接等待超時的時間 max-wait: 30000 # 配置間隔多久才進行一次檢測,檢測須要關閉的空閒鏈接,單位是毫秒 time-between-eviction-runs-millis: 60000 # 配置一個鏈接在池中最小生存的時間,單位是毫秒 min-evictable-idle-time-millis: 300000 # 驗證數據庫鏈接的有效性 validation-query: select '1' from dual test-while-idle: true test-on-borrow: false test-on-return: false # 打開PSCache,而且指定每一個鏈接上PSCache的大小 pool-prepared-statements: true max-open-prepared-statements: 20 max-pool-prepared-statement-per-connection-size: 20 # 配置監控統計攔截的filters,去掉後監控界面sql沒法統計,'wall'用於防火牆 filters: stat,wall,slf4j # 合併多個DruidDataSource的監控數據 use-global-data-source-stat: true connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500 stat-view-servlet: login-username: admin login-password: admin url-pattern: /druid/* allow: 127.0.0.1 reset-enable: false # 必須啓用,要不會404 enabled: true定位錯誤(druid源碼)
com.alibaba.druid.wall.WallFilter.init
java
public synchronized void init(DataSourceProxy dataSource) { if (dataSource == null) { LOG.error("dataSource should not be null"); } else { if (this.dbTypeName == null || this.dbTypeName.trim().length() == 0) { if (dataSource.getDbType() != null) { this.dbTypeName = dataSource.getDbType(); } else { this.dbTypeName = JdbcUtils.getDbType(dataSource.getRawJdbcUrl(), ""); } } if (this.dbTypeName == null) { this.dbTypeName = JdbcUtils.getDbType(dataSource.getUrl(), (String)null); } DbType dbType = DbType.of(this.dbTypeName); switch(dbType) { case mysql: case oceanbase: case drds: case mariadb: case h2: case presto: if (this.config == null) { this.config = new WallConfig("META-INF/druid/wall/mysql"); } this.provider = new MySqlWallProvider(this.config); break; case oracle: case ali_oracle: case oceanbase_oracle: if (this.config == null) { this.config = new WallConfig("META-INF/druid/wall/oracle"); } this.provider = new OracleWallProvider(this.config); break; case sqlserver: case jtds: if (this.config == null) { this.config = new WallConfig("META-INF/druid/wall/sqlserver"); } this.provider = new SQLServerWallProvider(this.config); break; case postgresql: case edb: case polardb: if (this.config == null) { this.config = new WallConfig("META-INF/druid/wall/postgres"); } this.provider = new PGWallProvider(this.config); break; case db2: if (this.config == null) { this.config = new WallConfig("META-INF/druid/wall/db2"); } this.provider = new DB2WallProvider(this.config); break; case sqlite: if (this.config == null) { this.config = new WallConfig("META-INF/druid/wall/sqlite"); } this.provider = new SQLiteWallProvider(this.config); break; case clickhouse: if (this.config == null) { this.config = new WallConfig("META-INF/druid/wall/clickhouse"); } this.provider = new ClickhouseWallProvider(this.config); break; default: throw new IllegalStateException("dbType not support : " + dbType + ", url " + dataSource.getUrl()); } this.provider.setName(dataSource.getName()); this.inited = true; } }
顯然this.dbTypeName
爲null
,從源碼分析可知由於咱們配置了p6spy
,jdbc的url上添加了:p6spy
致使druid沒法匹配對應dbType
,因此只須要手動配置下數據庫類型便可,我用的是mysql
,因此添加datasource.druid.dbType = mysql
即mysql
... datasource: driver-class-name: com.p6spy.engine.spy.P6SpyDriver url: jdbc:p6spy:mysql://127.0.0.1:3306/xxxxx?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&autoReconnect=true&serverTimezone=GMT%2B8 username: root password: xxxxx type: com.alibaba.druid.pool.DruidDataSource druid: db-type: mysql ...
這樣顯式定義dbType
就能解決問題web