Search code examples
springauthorizationshiro

Strange error occured in shiro doGetAuthorizationInfo method


I am encountered with a strange error for a few days,and still in puzzled,details are below:

I'm using apache shiro with spring,

after some work,I got ready to setup "doGetAuthorizationInfo" method,because I'm using "@RequiresRoles" in my controller,

I found if I invoke XXXService(or any service) more than once,the exception occur(first time invoke XXXService,everything work fine),so,I'm try to test "doGetAuthenticationInfo" in same Realm which used for login,I invoked XXXService or other services several times in the method,it works fine,

and I also tried to change different datasource component,

so I think it's not datasource component bug,

I didn't find the reason.

When I was using dbcp datasource,exception like below:

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.

No others are causing exception.

Any other place didn't found this problem.

Thanks for any help.


Solution

  • Through the efforts more than one day,I find something, I was using dataSourceProxy:

    <bean id="dataSourceProxy"
        class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
        <property name="targetDataSource" ref="dataSource" />
    </bean>
    
    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSourceProxy" />
    ...
    </bean>
    

    When I change to ref original datasource bean for entityManagerFactory:

    <bean id="entityManagerFactory"
            class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        ...
    </bean>
    

    The error disappear.