Spring Security SQL错误:0,SQLState:null

时间:2013-01-23 14:19:09

标签: spring spring-security

我的项目完全符合数据库加载所有数据,但Spring Security会抛出以下异常

10:58:08 WARN [JDBCExceptionReporter] SQL错误:0,SQLState:null 10:58:08 ERROR [JDBCExceptionReporter] com.mchange.v2.c3p0.ComboPooledDataSource [java.beans.IntrospectionException:java.lang.reflect.InvocationTargetException [numThreadsAwaitingCheckoutDefaultUser]]已关闭()

这是我的spring安全配置类

<http auto-config="true" use-expressions="false" authentication-manager-ref="authManager" access-decision-manager-ref="accessDecisionManager"
    access-denied-page="/unauthorized">
    <intercept-url pattern="/**" access="IS_AUTHENTICATED_FULLY" />

    <form-login 
        login-processing-url="/j_login" 
        authentication-failure-url="/login?erro=usuarioIncorreto"
        always-use-default-target="false"
        login-page="/login" 
        default-target-url="/" />

    <logout invalidate-session="true" 
        logout-success-url="/login"
        logout-url="/j_logout"
        delete-cookies="JSESSIONID" />

    <session-management invalid-session-url="/login?erro=novaSessao" 
        session-fixation-protection="newSession">
        <concurrency-control max-sessions="1" error-if-maximum-exceeded="false" />
    </session-management>
</http>

<authentication-manager >
    <authentication-provider user-service-ref="securityServiceTrack">
        <password-encoder hash="md5" />
    </authentication-provider>
</authentication-manager>

<beans:bean id="accessDecisionManager" class="org.springframework.security.access.vote.UnanimousBased">
    <beans:property name="decisionVoters">
        <beans:list>
            <beans:bean class="org.springframework.security.access.vote.AuthenticatedVoter" />

- &gt;                           

这是我的web.xml:

<display-name>Track Go Web</display-name>

<!-- ******************************************************* -->
<!-- Configuração do Spring -->
<!-- ******************************************************* -->

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/config/spring/applicationContext.xml
        /WEB-INF/config/spring/applicationContext-persistence.xml
        /WEB-INF/config/spring/applicationContext-security.xml
    </param-value>
</context-param>

<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>

<!-- Spring Security -->
<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
    <listener-class>
        org.springframework.security.web.session.HttpSessionEventPublisher
    </listener-class>
</listener> 

<!-- OpenEntityManagerInViewFilter -->
<filter>
    <filter-name>OpenEntityManagerInViewFilter</filter-name>
    <filter-class>
        org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
    </filter-class>
</filter>
<filter-mapping>
    <filter-name>OpenEntityManagerInViewFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<!-- ******************************************************* -->
<!-- Configuração do SiteMesh -->
<!-- ******************************************************* -->
 <filter>
    <filter-name>sitemesh</filter-name>
    <filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>sitemesh</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>


<!-- ******************************************************* -->
<!-- Configuração do VRaptor3 -->
<!-- ******************************************************* -->

<context-param>
    <param-name>br.com.caelum.vraptor.encoding</param-name>
    <param-value>UTF-8</param-value>
</context-param>
<!-- Define Messages Bundle -->

- &GT; javax.servlet.jsp.jstl.fmt.localizationContext&LT; / PARAM-名称&gt; - &GT; 消息&LT; / PARAM值&GT; - &GT; - &GT;                   javax.servlet.jsp.jstl.fmt.locale         pt_BR表示           - &GT; vraptor.jasperMaker&LT; / PARAM-名称&gt; - &GT; / WEB-INF /报告&LT; / PARAM值&GT; - &GT; - &GT;

<filter>
    <filter-name>vraptor</filter-name>
    <filter-class>br.com.caelum.vraptor.VRaptor</filter-class>
</filter>

<filter-mapping>
    <filter-name>vraptor</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>REQUEST</dispatcher>
</filter-mapping>

这是我的持久性配置文件

<!-- ********************************************* -->
<!-- DataSource condfig-->
<!-- ********************************************* -->



<context:property-placeholder location="classpath:configuracoes.properties" />

 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <property name="driverClass" value="${trackgoweb.jdbc.driverclass}" />
    <property name="jdbcUrl" value="${trackgoweb.jdbc.url}" />
    <property name="user" value="${trackgoweb.jdbc.username}" />
    <property name="password" value="${trackgoweb.jdbc.password}" />
    <property name="maxPoolSize" value="10" />
    <property name="maxStatements" value="0" />
    <property name="minPoolSize" value="3" />
    <property name="checkoutTimeout" value="30000" />
</bean>

<!-- Configuraçãoes relativas a acesso a dados -->
<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

    <property name="dataSource" ref="dataSource"/>

    <property name="jpaDialect">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"></bean>
    </property>
    <property name="jpaVendorAdapter">
        <bean
            class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="showSql" value="true" />
            <property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect" />
        </bean>
    </property>
    <property name="jpaProperties">
        <props>
            <prop key="hibernate.format_sql">true</prop>
            <prop key="hibernate.query.substitutions">true 'S',false 'N',yes 'S',no 'N'</prop>
            <prop key="hibernate.query.jpaql_strict_compliance">true</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
        </props>
    </property>
</bean>

<!-- Transaction Manager exclusivo para JPA -->
<bean id="transactionManager"
    class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
    <property name="jpaDialect">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"></bean>
    </property>
</bean>

1 个答案:

答案 0 :(得分:1)

我通过删除数据源bean上的distroy上的会话闭包来解决这个问题

<context:property-placeholder location="classpath:configuracoes.properties" />

 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="driverClass" value="${trackgoweb.jdbc.driverclass}" />
    <property name="jdbcUrl" value="${trackgoweb.jdbc.url}" />
    <property name="user" value="${trackgoweb.jdbc.username}" />
    <property name="password" value="${trackgoweb.jdbc.password}" />
    <property name="maxPoolSize" value="10" />
    <property name="maxStatements" value="0" />
    <property name="minPoolSize" value="3" />
    <property name="checkoutTimeout" value="30000" />
</bean>