定義了一個mybatis 過濾日志的攔截器
@Component
@Intercepts({
@Signature(type = Executor.class, method = "update", args = { MappedStatement.class, Object.class }),
@Signature(type = Executor.class, method = "query", args = { MappedStatement.class, Object.class,
RowBounds.class, ResultHandler.class }),
@Signature(type = Executor.class, method = "query", args = { MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class, CacheKey.class, BoundSql.class })
})
public class SqlDIYInterceptor implements Interceptor {
public Object intercept(Invocation invocation) throws Throwable {
//處理邏輯
}
public Object plugin(Object target) {
return Plugin.wrap(target, this);
}
public void setProperties(Properties properties0) {
this.properties = properties0;
}
}
定義了@Configuration
并且在代碼中
public SqlSessionFactory paySqlSessionFactory(@Qualifier("DataSource") DataSource dataSource) throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:/mapper*.xml"));
bean.setPlugins(new Interceptor[]{new SqlDIYInterceptor()});
return bean.getObject();
}定義了日志輸出等級 涉及到DAO的
level:
mapper: debug
以上配置后無效
后來我換了一種方式yml中加入了 config-location:mybatis.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<plugins>
<plugin interceptor="cn..SqlDIYInterceptor">
</plugin>
</plugins>
</configuration>
同樣也不起作用
想請教下 我該從什么角度、細節定位問題呢?
uj5u.com熱心網友回復:
是不是沒掃描到,你在啟動類上加這個攔截器的掃描路徑試試uj5u.com熱心網友回復:
paySqlSessionFactory 這個里面列印一個日志,看看是否初始化成功了,org.mybatis.spring.SqlSessionFactoryBean.setPlugins既然采取了new,那么就不需要@Component這個了,如果想更spring一些,那么 paySqlSessionFactory(@Qualifier("DataSource") DataSource dataSource)可以改成 paySqlSessionFactory(@Qualifier("DataSource") DataSource dataSource,@Qualifier("sqlDIYInterceptor")) SqlDIYInterceptor interceptor轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/32670.html
標籤:Web 開發
上一篇:Java批量資料對比(2萬條資料與資料庫50萬條資料比對)查詢怎么提升效率,oracle資料庫。
下一篇:報錯java.util.zip.ZipException: invalid LOC header (bad signature)
