[英]Spring 4.2.1 on GAE and java.util.ResourceBundle$Control is a restricted class
If I move from Spring 4.1.7.RELEASE to 4.2.1.RELEASE Google App Engine raises java.lang.NoClassDefFoundError
如果我从Spring 4.1.7.RELEASE转到4.2.1.RELEASE Google App Engine会引发
java.lang.NoClassDefFoundError
when Spring Security throws AccessDeniedException
(AffirmativeBased.java:83) 当Spring Security抛出
AccessDeniedException
(AffirmativeBased.java:83)
I know I do not have access to requested resource. 我知道我无法访问所请求的资源。 I expect spring to show login page after that but since Spring 4.2 it does not work :(
我希望春天在那之后显示登录页面,但自从春季4.2它不起作用:(
[INFO] java.lang.NoClassDefFoundError: java.util.ResourceBundle$Control is a restricted class. Please see the Google App Engine developer's guide for more details.
[INFO] at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:52)
[INFO] at org.springframework.context.support.ResourceBundleMessageSource$MessageSourceControl.<init>(ResourceBundleMessageSource.java:417)
[INFO] at org.springframework.context.support.ResourceBundleMessageSource$MessageSourceControl.<init>(ResourceBundleMessageSource.java:417)
[INFO] at org.springframework.context.support.ResourceBundleMessageSource.doGetBundle(ResourceBundleMessageSource.java:314)
[INFO] at org.springframework.context.support.ResourceBundleMessageSource.getResourceBundle(ResourceBundleMessageSource.java:284)
[INFO] at org.springframework.context.support.ResourceBundleMessageSource.resolveCodeWithoutArguments(ResourceBundleMessageSource.java:234)
[INFO] at org.springframework.context.support.AbstractMessageSource.getMessageInternal(AbstractMessageSource.java:218)
[INFO] at org.springframework.context.support.AbstractMessageSource.getMessage(AbstractMessageSource.java:136)
[INFO] at org.springframework.context.support.MessageSourceAccessor.getMessage(MessageSourceAccessor.java:83)
[INFO] at org.springframework.security.access.vote.AffirmativeBased.decide(AffirmativeBased.java:83)
[INFO] at org.springframework.security.access.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:232)
[INFO] at org.springframework.security.access.intercept.aspectj.AspectJMethodSecurityInterceptor.invoke(AspectJMethodSecurityInterceptor.java:43)
[INFO] at org.springframework.security.access.intercept.aspectj.aspect.AnnotationSecurityAspect.ajc$around$org_springframework_security_access_intercept_aspectj_aspect_AnnotationSecurityAspect$1$c4d57a2b(AnnotationSecurityAspect.aj:63)
[INFO] at xx.xxx.controllers.PortalController.home(PortalController.java:51)
To run Spring 4.2.1 on GAE and use global method security I had to set message source to StaticMessageSource instead of ResourceBundleMessageSource which caused the problem. 要在GAE上运行Spring 4.2.1并使用全局方法安全性,我必须将消息源设置为StaticMessageSource而不是导致问题的ResourceBundleMessageSource。 Unfortunately declaring the messageSource bean is not only one thing that has to be done.
不幸的是,声明messageSource bean不仅是必须要做的事情。
@Bean(name = "messageSource")
public MessageSource messageSource() {
StaticMessageSource messageSource = new StaticMessageSource();
return messageSource;
}
AffirmativeBased access decision manager which is used here is created by method GlobalMethodSecurityConfiguration.accessDecisionManager() and is not a Spring bean so setMessageSource() method is not executed so it is not MessageSourceAware
. 这里使用的AffirmativeBased访问决策管理器是由方法GlobalMethodSecurityConfiguration.accessDecisionManager()创建的,不是Spring bean,因此不执行setMessageSource()方法,因此它不是
MessageSourceAware
。 The solution for that is to set this messageSource manually: 解决方案是手动设置此messageSource:
@Configuration
@EnableGlobalMethodSecurity
public class MethodSecurityConfiguration extends GlobalMethodSecurityConfiguration {
@Inject
private MessageSource messageSource;
@Override
protected AccessDecisionManager accessDecisionManager() {
AffirmativeBased manager = (AffirmativeBased)super.accessDecisionManager();
manager.setMessageSource(messageSource);
return manager;
}
}
After a bit of trial and error, the following seemed to work OK for me: 经过一些试验和错误,以下似乎对我有效:
Update Spring config to use ReloadableResourceBundleMessageSource instead of ResourceBundleMessageSource, eg in XML 更新Spring配置以使用ReloadableResourceBundleMessageSource而不是ResourceBundleMessageSource,例如在XML中
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basename" value="/WEB-INF/i18n/messages" /> </bean> <bean id =“messageSource”class =“org.springframework.context.support.ReloadableResourceBundleMessageSource”> <property name =“basename”value =“/ WEB-INF / i18n / messages”/> </ bean>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.