java – 无法将String类型的值转换为MethodSecurityMetadataSource(Spring 3.1)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – 无法将String类型的值转换为MethodSecurityMetadataSource(Spring 3.1),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含6191字,纯文字阅读大概需要9分钟。
内容图文
从Spring 3.0.0升级到3.1.0之后
我无法实例化MethodSecurityInterceptor bean.
这是原始的bean定义,在Spring 3.0.0中有效:
<bean id="methodSecurityInterceptor" class="org.springframework.security.access.interce pt.aopalliance.MethodSecurityInterceptor">
<property name="authenticationManager" ref="myAuthenticationManager" />
<property name="accessDecisionManager" ref="myAccessDecisionManager" />
<property name="securityMetadataSource">
<value>
com.myPackage.foo=ROLE_ADMIN
com.myPackage.bar=ROLE_ADMIN
com.myPackage.inner.*=ROLE_ADMIN
</value>
</bean>
抛出此异常:
exception is org.springframework.beans.ConversionNotSupportedEx ception: Failed to
convert property value of type 'java.lang.String' to required type
'org.springframework.security.access.method.Method SecurityMetadataSource' for property 'securityMetadataSource'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.springframework.security.access.method.MethodS ecurityMetadataSource] for property 'securityMetadataSource': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 93)
at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:290 )
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:196)
at org.springframework.aop.support.AbstractBeanFactor yPointcutAdvisor.getAdvice(AbstractBeanFactoryPoin tcutAdvisor.java:80)
at org.springframework.aop.aspectj.AspectJProxyUtils. isAspectJAdvice(AspectJProxyUtils.java:67)
at org.springframework.aop.aspectj.AspectJProxyUtils. makeAdvisorChainAspectJCapableIfNecessary(AspectJP roxyUtils.java:49)
at org.springframework.aop.aspectj.autoproxy.AspectJA wareAdvisorAutoProxyCreator.extendAdvisors(AspectJ AwareAdvisorAutoProxyCreator.java:101)
at org.springframework.aop.framework.autoproxy.Abstra ctAdvisorAutoProxyCreator.findEligibleAdvisors(Abs tractAdvisorAutoProxyCreator.java:88)
at org.springframework.aop.framework.autoproxy.Abstra ctAdvisorAutoProxyCreator.getAdvicesAndAdvisorsFor Bean(AbstractAdvisorAutoProxyCreator.java:68)
at org.springframework.aop.framework.autoproxy.Abstra ctAutoProxyCreator.wrapIfNecessary(AbstractAutoPro xyCreator.java:359)
at org.springframework.aop.framework.autoproxy.Abstra ctAutoProxyCreator.postProcessAfterInitialization( AbstractAutoProxyCreator.java:322)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyBeanPostProcessors AfterInitialization(AbstractAutowireCapableBeanFac tory.java:407)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1426)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:519)
... 24 more
Caused by: org.springframework.beans.ConversionNotSupportedEx ception: Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.security.access.method.Method SecurityMetadataSource' for property 'securityMetadataSource'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.springframework.security.access.method.MethodS ecurityMetadataSource] for property 'securityMetadataSource': no matching editors or conversion strategy found
at org.springframework.beans.BeanWrapperImpl.convertI fNecessary(BeanWrapperImpl.java:481)
at org.springframework.beans.BeanWrapperImpl.convertF orProperty(BeanWrapperImpl.java:518)
at org.springframework.beans.BeanWrapperImpl.convertF orProperty(BeanWrapperImpl.java:512)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.convertForProperty(Abst ractAutowireCapableBeanFactory.java:1371)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1330)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:1086)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:517)
... 40 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.springframework.security.access.method.MethodS ecurityMetadataSource] for property 'securityMetadataSource': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.co nvertIfNecessary(TypeConverterDelegate.java:233)
at org.springframework.beans.BeanWrapperImpl.convertI fNecessary(BeanWrapperImpl.java:466)
... 46 more
任何帮助将不胜感激.
解决方法:
在Spring 3.1中删除了负责将securityMetadataSource值中出现的字符串转换为MethodSecurityMetadataSource实例的类 – MethodSecurityMetadataSourceEditor,这就是您获得异常的原因.
虽然在3.1:MethodSecurityMetadataSourceBeanDefinitionParser中添加了一个新类.它在XML文件中为您提供了一个新标记.
所以,而不是:
<value>
com.myPackage.foo=ROLE_ADMIN
com.myPackage.bar=ROLE_ADMIN
com.myPackage.inner.*=ROLE_ADMIN
</value>
你现在可以写:
<s:method-security-metadata-source>
<s:protect method="com.myPackage.foo" access="ROLE_ADMIN"/>
<s:protect method="com.myPackage.bar" access="ROLE_ADMIN"/>
<s:protect method="com.myPackage.inner.*" access="ROLE_ADMIN"/>
</s:method-security-metadata-source>
P.S:
不要忘记将xml架构更新为3.1:
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">
内容总结
以上是互联网集市为您收集整理的java – 无法将String类型的值转换为MethodSecurityMetadataSource(Spring 3.1)全部内容,希望文章能够帮你解决java – 无法将String类型的值转换为MethodSecurityMetadataSource(Spring 3.1)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。