What do you mean you would like to "read" a custom bean? If you need
access to one bean from another bean in the context then just use the
normal dependency injection mechanism (declare a setFoo method and use
<property name="foo" ref="..." />). If you need the ApplicationContext
within one of your Spring beans (e.g. to look up prototype beans
repeatedly) then you can have your bean implement BeanFactoryAware or
any of the other *Aware interfaces.
If you want access to a Spring bean from a non-Spring class you don't
need to create your own ClassPathApplicationContext; you can use
WebApplicationContextUtils.getWebApplicationContext(ServletContext) to
get a reference to the context that was loaded by the ContextLoaderListener.
If you want more details I'll need a better idea of what exactly you're
trying to do...
Ian
Bruno Melloni wrote:
> I think I am missing the point on something basic. Would somebody enlighten
> me?
>
> I would like to read a custom bean that I added to the cxf/spring context
> file. What is the correct syntax for reading it?
>
> My configuration:
>
> a) In web.xml:
>
> <context-param>
> <param-name>contextConfigLocation</param-name>
>
> <param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value>
> </context-param>
> <listener>
>
> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
> </listener>
>
> b) Context files:
>
> WEB-INF/applicationContext-ws.xml (for the web service)
> WEB-INF/classes/applicationContext-app.xml (for other beans)
>
> c) Loading beans from applicationContext-app.xml (works OK):
>
> ApplicationContext ctx = new ClassPathXmlApplicationContext(
> "applicationContext-app.xml" );
> myBean = (MyBeanClass)ctx.getBean("myBean");
>
> d) Loading beans from applicationContext-ws.xml does not work. I tried:
>
> - similar code to that in (c)
> - autowiring
> - using the ServletContextAware interface (crazy idea of course - CXF is
> not Spring MVC)
>
> Any help will be greatly welcome... I know this must be terribly basic and I
> am feeling really stupid.
--
Ian Roberts | Department of Computer Science
[email protected] | University of Sheffield, UK