【发布时间】:2012-09-28 23:18:08
【问题描述】:
我正在尝试使用 Spring3.1 实现部分级别的安全性。使用 Thymeleaf2.0 作为我的视图部分。这是我为此所做的配置,
使用的罐子## - 所有 spring3.1 罐子 和 thymeleaf-extras-springsecurity3.jar(版本 1.0.0.beta-1)
SpringWebFlow-Servlet.xml
<bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine">
...
<property name="additionalDialects">
<set>
<bean class="org.thymeleaf.extras.springsecurity3.dialect.SpringSecurityDialect"/>
</set>
</property>
...
</bean>
<bean id="webexpressionHandler" class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler" />
spring-security.xml
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/productSelection" access="hasRole('ROLE_ADMIN')"/>
.....
</http>
xxx.html
<div sec:authorize="hasRole('ROLE_ADMIN')">
This only be seen if authenticated user has role ROLE_ADMIN.
</div>
问题
获取异常说明: 在 applicationContext 中找不到可见的 WebSecurityExpressionHandler 实例
在 Spring3.1 中,DefaultWebSecurityExpressionHandler 没有实现 WebSecurityExpressionHandler,该接口已被弃用。请让我知道解决方法,因为 Thymeleaf 正在尝试搜索 ApplicationContext 中不可用的 WebSecurityExpressionHandler 实例。
【问题讨论】:
-
您使用的是最新版本吗?
DefaultWebSecurityExpressionHandler确实实现了WebSecurityExpressionHandler。您可以查看the source 进行检查。看thymeleaf项目,只提到了Spring Security 3.0.x,所以可能不兼容3.1。 -
@Luke,我使用的是 3.1.0,现在我已将其替换为 3.1.2。这并没有解决我的问题,但至少该异常已经消失。看起来是兼容性问题。谢谢!