查看信息
trationDelegate $ BeanPostProcessorChecker:Bean' dataSource' [class com.alibaba.druid.pool.DruidDataSource]类型不适合所有BeanPostProcessors处理(例如:不符合自动代理条件)
我在这个网站上寻找了一些问题,但我无法理解。 我使用spring bootI mybatis,当我把它们组合起来时就错了。
@Configuration
@MapperScan(basePackages =" w.p.j.dao") 公共课MybatisConfig {
private Logger logger = LoggerFactory.getLogger(this.getClass().getName());
@Autowired
private DruidDataSourceEntity druidDataSourceEntity;
@Bean
public DataSource dataSource() {
logger.info("------------druidDataSourceEntity------" + druidDataSourceEntity);
//加载配置文件属性
DruidDataSource dataSource = new DruidDataSource();
dataSource.setDriverClassName(druidDataSourceEntity.getDriverClassName());
dataSource.setUsername(druidDataSourceEntity.getUsername());
dataSource.setPassword(druidDataSourceEntity.getPassword());
dataSource.setUrl(druidDataSourceEntity.getUrl());
dataSource.setMaxActive(druidDataSourceEntity.getMaxActive());
dataSource.setValidationQuery(druidDataSourceEntity.getValidationQuery());
dataSource.setTestOnBorrow(druidDataSourceEntity.isTestOnBorrow());
dataSource.setTestOnReturn(druidDataSourceEntity.isTestOnReturn());
dataSource.setTestWhileIdle(druidDataSourceEntity.isTestWhileIdle());
dataSource.setTimeBetweenEvictionRunsMillis(druidDataSourceEntity.getTimeBetweenEvictionRunsMillis());
dataSource.setMinEvictableIdleTimeMillis(druidDataSourceEntity.getMinEictableIdleTimeMillis());
dataSource.setPoolPreparedStatements(druidDataSourceEntity.isPoolPreparedStatements());
dataSource.setMaxOpenPreparedStatements(druidDataSourceEntity.getMaxOpenPreparedStatements());
try {
dataSource.setFilters(druidDataSourceEntity.getFilters());
} catch (SQLException e) {
e.printStackTrace();
}
return dataSource;
}
public Resource[] getResource(String basePackage, String pattern) throws IOException {
String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
+ ClassUtils.convertClassNameToResourcePath(new StandardEnvironment()
.resolveRequiredPlaceholders(basePackage)) + "/" + pattern;
Resource[] resources = new PathMatchingResourcePatternResolver().getResources(packageSearchPath);
return resources;
}
@Bean
public SqlSessionFactory sqlSessionFactory() throws Exception {
logger.info("------> sqlSessionFactory");
final SqlSessionFactoryBean sqlSessionFactory = new SqlSessionFactoryBean();
sqlSessionFactory.setDataSource(dataSource());
sqlSessionFactory.setConfigLocation(new ClassPathResource("mybatis-config.xml"));
sqlSessionFactory.setFailFast(true);
sqlSessionFactory.setMapperLocations(getResource("mapper", "**/*.xml"));
//配置插件
return sqlSessionFactory.getObject();
}
@Bean
public DataSourceTransactionManager transactionManager() {
logger.info("> transactionManager");
return new DataSourceTransactionManager(dataSource());
}
@Bean
@Scope(value = "prototype")//这个注解蛮重要的,保证线程安全
public SqlSessionTemplate sqlSessionTemplate() {
try {
logger.info("SqlSessionTemplate---");
return new SqlSessionTemplate(sqlSessionFactory());
} catch (Exception e) {
e.printStackTrace();
}
logger.info("---sqlSesson----","空");
return null;
}
@PostConstruct
public void postConstruct() {
logger.info("jdbc.settings={}", druidDataSourceEntity);
logger.info("sqlSession",sqlSessionTemplate());
}
}
当我的配置是XMl时,使用spring mvc就可以了。 可能是由于但我不知道如果你有一个好主意或者你有一个更好的解决方案或者你可以给我一个演示,我怎么能在春季启动时做,请告诉我。我非常感谢你的帮助