0

I tried to change the scope of a bean using @Scope annotation. That bean is actually working as MessageSource and used for internationalization purpose.

The schema in mvc-dispacher-servlet.xml is as follows:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
     xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans     
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

Exception described in console is as follows:

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Cannot locate BeanDefinitionParser for element [scoped-proxy]

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
Prashant
  • 692
  • 2
  • 11
  • 26
  • Not enough information in your post. Is your bean replacing the default messagesource, just using it or is a normal bean doing a similar thing? – Martin Frey Mar 17 '13 at 06:25
  • @Martin: It is a normal bean but internally it is having access to messagesource through which i18n is implemented, rather than passing locale in each methd calling I declared a variable webLocale to the captured while login and that will be a constant argument which will be passed while calling getMessage() method of messagesource – Prashant Mar 17 '13 at 06:31

2 Answers2

0

Ok. If its a normal bean then most likely you are just missing the xml parser for the scope tag. To be able to use scoped proxies you need to register aop:scoped-proxy.

There is a similar question on SO: Accessing a session-scoped bean inside a controller

Which results in:

http://static.springsource.org/spring/docs/3.0.x/reference/beans.html#beans-factory-scopes-other-injection

Else you should easily find some tutorials on this topic through google.

Community
  • 1
  • 1
Martin Frey
  • 10,025
  • 4
  • 25
  • 30
0

It is likely that you have a bean-scoped option outside the bean (I made such mistake and got an error msg like yours) :

<beans>
...
<aop:config proxy-target-class="true"/>
<aop:scoped-proxy proxy-target-class="true"/>
<aop:aspectj-autoproxy proxy-target-class="true"/>
...

Just put that option inside of the bean declaration:

<bean ... target="step">
    <aop:scoped-proxy proxy-target-class="true"/>
</bean>

One more thing - I got such error only for scoped beans.

sergpank
  • 988
  • 10
  • 18