weblogic 12.1.2 和 spring-security 4.0.3 发布问题

weblogic 12.1.2 and spring-security 4.0.3 publishing issue

我正在使用 spring 4.23,spring-security 4.03 开发一个项目。该项目与 weblogic maven 插件一起工作正常,我可以使用插件部署到 weblogic 或使用 maven 将其打包到 war 并在管理控制台手动部署。

但是当我使用发布功能时发生了奇怪的事情并且发布失败了,我很确定我的 SecurityConfig 文件中有 @EnableWebSecurity 和 @Configuration

请帮我找出问题所在,谢谢。

错误如下:

weblogic.application.ModuleException: java.lang.IllegalStateException: org.springframework.security.config.annotation.ObjectPostProcessor is a required bean. Ensure you have used @EnableWebSecurity and @Configuration

java.lang.Exception: Exception received from deployment driver. See Error Log view for more detail.
  at oracle.eclipse.tools.weblogic.server.internal.DeploymentProgressListener.watch(DeploymentProgressListener.java:189)
  at oracle.eclipse.tools.weblogic.server.internal.WlsJ2EEDeploymentHelper.redeploy(WlsJ2EEDeploymentHelper.java:644)
  at oracle.eclipse.tools.weblogic.server.internal.WlsJ2EEDeploymentHelper.deploy(WlsJ2EEDeploymentHelper.java:474)
  at oracle.eclipse.tools.weblogic.server.internal.WeblogicServerBehaviour.publishWeblogicModules(WeblogicServerBehaviour.java:1455)
  at oracle.eclipse.tools.weblogic.server.internal.WeblogicServerBehaviour.publishToServer(WeblogicServerBehaviour.java:913)
  at oracle.eclipse.tools.weblogic.server.internal.WeblogicServerBehaviour.publishOnce(WeblogicServerBehaviour.java:704)
  at oracle.eclipse.tools.weblogic.server.internal.WeblogicServerBehaviour.publish(WeblogicServerBehaviour.java:555)
  at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publish(ServerBehaviourDelegate.java:774)
  at org.eclipse.wst.server.core.internal.Server.publishImpl(Server.java:3172)
  at org.eclipse.wst.server.core.internal.Server$PublishJob.run(Server.java:345)
  at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Caused by: weblogic.application.ModuleException: java.lang.IllegalStateException: org.springframework.security.config.annotation.ObjectPostProcessor is a required bean. Ensure you have used @EnableWebSecurity and @Configuration
  at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:140)
  at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
  at weblogic.application.internal.flow.ModuleStateDriver.next(ModuleStateDriver.java:213)
  at weblogic.application.internal.flow.ModuleStateDriver.next(ModuleStateDriver.java:208)
  at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
  at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:70)
  at weblogic.application.internal.flow.StartModulesFlow.activate(StartModulesFlow.java:24)
  at weblogic.application.internal.BaseDeployment.next(BaseDeployment.java:729)
  at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
  at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:258)
  at weblogic.application.internal.SingleModuleDeployment.activate(SingleModuleDeployment.java:48)
  at weblogic.application.internal.DeploymentStateChecker.activate(DeploymentStateChecker.java:165)
  at weblogic.deploy.internal.targetserver.AppContainerInvoker.activate(AppContainerInvoker.java:80)
  at weblogic.deploy.internal.targetserver.operations.AbstractOperation.activate(AbstractOperation.java:586)
  at weblogic.deploy.internal.targetserver.operations.ActivateOperation.activateDeployment(ActivateOperation.java:148)
  at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doCommit(ActivateOperation.java:114)
  at weblogic.deploy.internal.targetserver.operations.AbstractOperation.commit(AbstractOperation.java:339)
  at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentCommit(DeploymentManager.java:846)
  at weblogic.deploy.internal.targetserver.DeploymentManager.activateDeploymentList(DeploymentManager.java:1275)
  at weblogic.deploy.internal.targetserver.DeploymentManager.handleCommit(DeploymentManager.java:442)
  at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.commit(DeploymentServiceDispatcher.java:176)
  at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doCommitCallback(DeploymentReceiverCallbackDeliverer.java:195)
  at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access0(DeploymentReceiverCallbackDeliverer.java:13)
  at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.run(DeploymentReceiverCallbackDeliverer.java:68)
  at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:550)
  at weblogic.work.ExecuteThread.execute(ExecuteThread.java:295)
  at weblogic.work.ExecuteThread.run(ExecuteThread.java:254)
Caused by: java.lang.IllegalStateException: org.springframework.security.config.annotation.ObjectPostProcessor is a required bean. Ensure you have used @EnableWebSecurity and @Configuration


  at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.postProcess(WebSecurityConfigurerAdapter.java:79)
  at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.getHttp(WebSecurityConfigurerAdapter.java:172)
  at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.init(WebSecurityConfigurerAdapter.java:290)
  at com.gammon.pcms.config.SecurityConfig.init(SecurityConfig.java:0)
  at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.init(WebSecurityConfigurerAdapter.java:67)
  at com.gammon.pcms.config.SecurityConfig.init(SecurityConfig.java:0)
  at com.gammon.pcms.config.SecurityConfig$$EnhancerBySpringCGLIB$e1b5df.init(<generated>:0)
  at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.init(AbstractConfiguredSecurityBuilder.java:370)
  at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.doBuild(AbstractConfiguredSecurityBuilder.java:324)
  at org.springframework.security.config.annotation.AbstractSecurityBuilder.build(AbstractSecurityBuilder.java:41)
  at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.springSecurityFilterChain(WebSecurityConfiguration.java:105)
  at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$$EnhancerBySpringCGLIB$$d9c7728c.CGLIB$springSecurityFilterChain(<generated>:0)
  at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$$EnhancerBySpringCGLIB$$d9c7728c$$FastClassBySpringCGLIB$$d5f1163a.invoke(<generated>:0)
  at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
  at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:318)
  at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$$EnhancerBySpringCGLIB$$d9c7728c.springSecurityFilterChain(<generated>:0)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:606)
  at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
  at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:306)
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:296)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:838)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
  at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446)
  at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328)
  at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
  at weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.java:661)
  at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
  at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
  at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
  at weblogic.servlet.internal.EventsManager.executeContextListener(EventsManager.java:241)
  at weblogic.servlet.internal.EventsManager.notifyContextCreatedEvent(EventsManager.java:198)
  at weblogic.servlet.internal.EventsManager.notifyContextCreatedEvent(EventsManager.java:186)
  at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1783)
  at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:2807)
  at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1661)
  at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:822)
  at weblogic.application.internal.ExtensibleModuleWrapper$StartStateChange.next(ExtensibleModuleWrapper.java:360)
  at weblogic.application.internal.ExtensibleModuleWrapper$StartStateChange.next(ExtensibleModuleWrapper.java:356)
  at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
  at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:138)

我在下面 link 的帮助下解决了这个问题:

https://github.com/spring-projects/spring-loaded/issues/49

我在我的 SecurityConfig 中覆盖了以下方法:

@Override
@Autowired
public void setObjectPostProcessor(ObjectPostProcessor<Object> objectPostProcessor) {
    super.setObjectPostProcessor(objectPostProcessor);
}

@Override
@Autowired
public void setApplicationContext(ApplicationContext context) {
    super.setApplicationContext(context);
}

@Override
@Autowired
public void setAuthenticationConfiguration(AuthenticationConfiguration authenticationConfiguration) {
    super.setAuthenticationConfiguration(authenticationConfiguration);
}

看起来发布的 class 加载器通过发布和 maven/manual 部署工作不同,一些 @Autowired 不工作。

我有一个基础 class 供其他控制器扩展,但 @Autowired 不工作,我必须 @Override setter in child class...

public abstract class GWTSpringController extends PersistentRemoteService implements Controller, ServletContextAware {
        @Override
        @Autowired // <-- this not work
        public void setBeanManager(PersistentBeanManager manager) {
            super.setBeanManager(manager);
        }
        ...
}

@Service
public class UserServiceController extends GWTSpringController implements UserServiceRemote{
    @Override
    @Autowired // I need to override the setter in all child class...
    public void setBeanManager(PersistentBeanManager manager) {
        super.setBeanManager(manager);
    }
    ...
}