Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AbstractAutoProxyCreator throws IllegalStateException when using Apache Orchestra conversations [SPR-16347] #20894

Closed
spring-issuemaster opened this issue Jan 4, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Jan 4, 2018

Roland Bachlechner opened SPR-16347 and commented

I tried to migrate our applications from Spring 4 to Spring 5 and got the following problem. Defining and accessing a bean with orchestra conversation scope leads to this stacktrace:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personDao' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: BeanFactory required for resolving interceptor names
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:591)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$1(AbstractBeanFactory.java:348)
	at org.apache.myfaces.orchestra.conversation.spring.AbstractSpringOrchestraScope.getRealBean(AbstractSpringOrchestraScope.java:370)
	at org.apache.myfaces.orchestra.conversation.spring.ScopedBeanTargetSource.getTarget(ScopedBeanTargetSource.java:73)
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)
	at mycompany.persistence.dao.PersonDao$$EnhancerBySpringCGLIB$$6faf3db0.toString(<generated>)
	at com.sun.facelets.util.DevTools.writeVariables(DevTools.java:168)
	at com.sun.facelets.util.DevTools.writeVariables(DevTools.java:145)
	at com.sun.facelets.util.DevTools.debugHtml(DevTools.java:109)
	at com.sun.facelets.FaceletViewHandler.handleRenderException(FaceletViewHandler.java:692)
	at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:660)
	at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
	at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:189)
	at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
	at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:154)
	at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:260)
	at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:366)
	at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:493)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at mycompany.presentation.MySpecificFilter.doFilter(MySpecificFilter.java:46)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.myfaces.orchestra.filter.OrchestraServletFilter.doFilter(OrchestraServletFilter.java:77)
	at org.apache.myfaces.orchestra.lib.CompoundFilter$1.doFilter(CompoundFilter.java:58)
	at org.apache.myfaces.orchestra.lib._NullFilter.doFilter(_NullFilter.java:45)
	at org.apache.myfaces.orchestra.lib.CompoundFilter.doFilter(CompoundFilter.java:63)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:595)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: BeanFactory required for resolving interceptor names
	at org.springframework.util.Assert.state(Assert.java:73)
	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.resolveInterceptorNames(AbstractAutoProxyCreator.java:547)
	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.buildAdvisors(AbstractAutoProxyCreator.java:514)
	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:463)
	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:355)
	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:304)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:438)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1714)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:583)
	... 54 more

I debugged the code and found the line AbstractAutoProxyCreator:547 (Spring 5.0.2) that asserts that the beanFactory is not null (the line has not been there in Spring 4). But the beanFactory field is annotated @Nullable.

I'm actually no sure if this is a bug but I didn't find a possibility to set the beanFactory field on the instance (actual class is org.apache.myfaces.orchestra.conversation.spring.OrchestraAdvisorBeanPostProcessor). The AbstractAutoProxyCreator class did not change that much between 4 and 5 and especially the method that throws the exception only fails because of the Assert.

The orchestra bean configuration looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

    <import resource="classpath*:/META-INF/spring-orchestra-init.xml"/>

    <bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
        <property name="scopes">
            <map>
                <entry key="conversation.manual">
                    <bean class="org.apache.myfaces.orchestra.conversation.spring.SpringConversationScope">
                        <property name="timeout" value="60"/>
                        <property name="advices">
                            <list>
                                <ref bean="persistentContextConversationInterceptor"/>
                            </list>
                        </property>
                    </bean>
                </entry>

                <entry key="conversation.access">
                	<bean
                		class="org.apache.myfaces.orchestra.conversation.spring.SpringConversationScope">
                		<property name="timeout" value="60" />
                		<property name="advices">
                			<list>
                				<ref
                					bean="persistentContextConversationInterceptor" />
                			</list>
                		</property>
                		<property name="lifetime" value="access" />
                	</bean>
                </entry>
            </map>
        </property>
    </bean>

    <bean id="persistentContextConversationInterceptor"
          class="org.apache.myfaces.orchestra.conversation.spring.PersistenceContextConversationInterceptor">
        <property name="persistenceContextFactory" ref="persistentContextFactory"/>
    </bean>

    <bean id="persistentContextFactory"
          class="org.apache.myfaces.orchestra.conversation.spring.JpaPersistenceContextFactory">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>

</beans>

Affects: 5.0.2

Referenced from: commits 0a06bce

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 7, 2018

Juergen Hoeller commented

Good catch: That assertion is in the wrong place; it only needs to kick in when there is an actual interceptor name to resolve within the for loop. Fixed for 5.0.3 now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.