我正在尝试执行我的 GWT 应用程序和 Spring Security 的集成。@PreAuthorize("hasRole('ROLE_USER')")
当我向我的 DAO 类的方法添加注释时,会出现以下异常:
没有定义类型 [server.dao.ElementServiceDAO] 的唯一 bean:预期的单个 bean 但找到 0
DaoServiceLocator 找不到 DAO bean,但在调试模式下,我在 ApplicationContext 实例中看到 elementServiceDAO bean。
我的 DAO 类如下所示:
@Service
public class ElementServiceDAO extends EntityDAO {
@PreAuthorize("hasRole('ROLE_USER')")
@SuppressWarnings("unchecked")
public Layer getFullRenderingTopology() {
...
}
}
DAO 服务定位器的代码:
public class DaoServiceLocator implements ServiceLocator {
@Override
public Object getInstance(final Class<?> clazz) {
try {
final HttpServletRequest request = RequestFactoryServlet
.getThreadLocalRequest();
final ServletContext servletContext = request.getSession()
.getServletContext();
final ApplicationContext context = WebApplicationContextUtils
.getWebApplicationContext(servletContext);
return context.getBean(clazz);
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
}
applicationContext-security.xml:
<authentication-manager>
<authentication-provider>
<user-service>
<user name="operator" password="operator" authorities="ROLE_USER, ROLE_ADMIN" />
<user name="guest" password="guest" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
<global-method-security pre-post-annotations="enabled" />
请给我任何建议!