用的是sping boot 2.0.3+druid-spring-boot-start 1.1.10 数据库是sqlserver
spring:
datasource:
druid:
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: **
username: **
password: **
initial-size: 10
max-active: 100
min-idle: 10
max-wait: 60000
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000
validation-query: SELECT 1
test-while-idle: true
test-on-borrow: false
test-on-return: false
use-global-data-source-stat: true
connection-properties: druid.stat.mergeSql=true
filters: stat
web-stat-filter:
url-pattern: /*
exclusions: /druid/*,*.js,*.gif,*.jpg,*.png,*.css,*.ico
enabled: true
session-stat-enable: true
session-stat-max-count: 10
#principal-cookie-name: loginUserCode
stat-view-servlet:
url-pattern: /druid/*
enabled: true
#login-username: admin
#login-password: admin
two:
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: **
username: **
password: **
initial-size: 10
max-active: 100
min-idle: 10
max-wait: 60000
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000
validation-query: SELECT 1
test-while-idle: true
test-on-borrow: false
test-on-return: false
filters: stat
use-global-data-source-stat: true
配置类
package cn.com.zowee.webmes.mybatis;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource;
@Configuration
@MapperScan(basePackages = "****", sqlSessionTemplateRef = "userSqlSessionTemplate")
public class userConfig {
@Bean(initMethod= "init" )
@Primary
public DataSource userDataSource() {
return DruidDataSourceBuilder.create().build();
}
@Bean
@Primary
public SqlSessionFactory userSqlSessionFactory(@Qualifier("userDataSource") DataSource dataSource) throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:dao/*.xml"));
return bean.getObject();
}
@Bean
@Primary
public DataSourceTransactionManager userTransactionManager(@Qualifier("userDataSource") DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
@Bean
@Primary
public SqlSessionTemplate userSqlSessionTemplate(@Qualifier("userSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
return new SqlSessionTemplate(sqlSessionFactory);
}
}
package cn.com.zowee.webmes.mybatis;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource;
@Configuration
@MapperScan(basePackages = "**", sqlSessionTemplateRef = "twoSqlSessionTemplate")
public class twoDataSourceConfig {
@Bean
@ConfigurationProperties("spring.datasource.druid.two")
public DataSource twoDataSource() {
return DruidDataSourceBuilder.create().build();
}
@Bean
public SqlSessionFactory twoSqlSessionFactory(@Qualifier("twoDataSource") DataSource dataSource) throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:dao/*.xml"));
return bean.getObject();
}
@Bean
public DataSourceTransactionManager twoTransactionManager(@Qualifier("twoDataSource") DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
@Bean
public SqlSessionTemplate twoSqlSessionTemplate(@Qualifier("twoSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
return new SqlSessionTemplate(sqlSessionFactory);
}
}
另外我也试过
spring:
datasource:
druid:
web-stat-filter:
url-pattern: /*
exclusions: /druid/*,*.js,*.gif,*.jpg,*.png,*.css,*.ico
enabled: true
session-stat-enable: true
session-stat-max-count: 10
#principal-cookie-name: loginUserCode
stat-view-servlet:
url-pattern: /druid/*
enabled: true
#login-username: admin
#login-password: admin
one:
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: **
username: **
password: **
initial-size: 10
max-active: 100
min-idle: 10
max-wait: 60000
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000
validation-query: SELECT 1
test-while-idle: true
test-on-borrow: false
test-on-return: false
use-global-data-source-stat: true
connection-properties: druid.stat.mergeSql=true
filters: stat
use-global-data-source-stat: true
two:
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: **
username: **
password: **
initial-size: 10
max-active: 100
min-idle: 10
max-wait: 60000
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000
validation-query: SELECT 1
test-while-idle: true
test-on-borrow: false
test-on-return: false
filters: stat
use-global-data-source-stat: true
配置好 连接数据库查询返回数据都正常,就是druid monitor里面什么数据都没有,连主页的项目信息都没有,请问是怎么回事
4条答案
按热度按时间whhtz7ly1#
找到原因了 是因为Spring Security的CSRF,导致druid/index.html 的post请求返回403
iyfamqjs2#
找到原因了 是因为Spring Security的CSRF,导致druid/index.html 的post请求返回403
我也碰到了,是直接 disable csrf 吗
i7uaboj43#
找到原因了 是因为Spring Security的CSRF,导致druid/index.html 的post请求返回403
我也碰到了,是直接 disable csrf 吗
我是这样干的
yi0zb3m44#
找到原因了 是因为Spring Security的CSRF,导致druid/index.html 的post请求返回403
我也碰到了,是直接 disable csrf 吗
我是这样干的
这个应该没有形成跨域,只不过 security 做了 csrf 方面的安全检查,感觉是这样