查詢某個模塊數據時,拋出如下異常:java
Caused by: java.sql.SQLException: sql injection violation, comment not allow : select count(*) FROM sys_x a WHERE 1=1 --澶囨敞 AND a.organization_id NOT IN( SELECT b.descendant_id FROM sys_y b WHERE b.path_length!=0)
at com.alibaba.druid.wall.WallFilter.checkInternal(WallFilter.java:800)
at com.alibaba.druid.wall.WallFilter.connection_prepareStatement(WallFilter.java:251)
at com.alibaba.druid.filter.FilterChainImpl.connection_prepareStatement(FilterChainImpl.java:473)
at com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl.prepareStatement(ConnectionProxyImpl.java:342)
at com.alibaba.druid.pool.DruidPooledConnection.prepareStatement(DruidPooledConnection.java:349)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy$TransactionAwareInvocationHandler.invoke(TransactionAwareDataSourceProxy.java:239)
at com.sun.proxy.$Proxy23.prepareStatement(Unknown Source)
at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.createPreparedStatement(PreparedStatementCreatorFactory.java:245)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:583)
... 59 more
複製代碼
<!--配置 druid 攔截過濾器-->
<bean id="wall-filter-config" class="com.alibaba.druid.wall.WallConfig" init-method="init">
<!-- 是否容許語句中存在註釋-->
<property name="commentAllow" value="true" />
</bean>
<bean id="wall-filter" class="com.alibaba.druid.wall.WallFilter">
<property name="config" ref="wall-filter-config" />
</bean>
複製代碼
而後在 Druid 數據源配置中,加入 Druid 攔截過濾器:spring
<!--druid 數據源-->
<bean id="druidDataSource" class="com.alibaba.druid.pool.DruidDataSource">
...
<!--配置 Druid 過濾器-->
<property name="proxyFilters">
<list>
...
<ref bean="wall-filter"/>
</list>
</property>
...
</bean>
複製代碼
重啓應用,看看問題是否是已經解決啦O(∩_∩)O哈哈~sql