I get "No session for current thread". I believe the problem is mixing declarative xml beans and annotated beans. Following this, I will return my configuration.
MyLibrary Project
Spring 3.1.4 Hibernate 4
applicationContext.xml
<tx:annotation-driven transaction-manager="transactionManager" />
<context:component-scan
base-package="com.mycompany.dao.core, com.mycompany.services.core,
com.mycompany.permissionEvaluator" />
<import resource="model-core-security.xml" />
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
... (sessionFactory ecc...)
core-model-security.xml
<bean id="expressionHandler"
class="org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler">
<property name="permissionEvaluator" ref="permissionEvaluator" />
</bean>
<security:global-method-security
pre-post-annotations="enabled">
<security:expression-handler ref="expressionHandler" />
</security:global-method-security>
With component scanning, I create beans: AccountService, AccountDAO and PermissionEvaluator.
AccountService.java (com.mycompany.services)
@Service("accountService")
@Transactional
public class AccountServiceImpl implements AccountService {
@Resource
private AccountDAO accountDAO;
...
}
AccountDAO.java (com.mycompany.dao)
@Repository
@Transactional
public class HibernateAccountDAOImpl implements AccountDAO {
...query...
}
(AccountService e AccountDAO is transactional)
Now, in AccountController.java , I call accountService.listAccounts () and everything is fine !
AccountService PermissionEvaluator ( ), AccountController accountService.listAccounts()
PermissionEvaluator.java(com.mycompany.permissionEvaluator)
Component("permissionEvaluator")
public class PermissionEvaluatorImpl implements PermissionEvaluator {
@Resource
private AccountService accountService;
...
}
PermissionEvaluator ( AccountService, AccountDAO), Handler bean, model-core-security.xml.
" "?