AnsweredAssumed Answered

Sping ApplicationContext

Question asked by dominict on Aug 27, 2006
Latest reply on Sep 7, 2006 by derek
Has anyone had problems obtaining a custom bean from a Web Service:

This works:

        ApplicationContext appCtx = null;
        HttpServletRequest request = (HttpServletRequest)MessageContext.getCurrentContext().getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
        ServletContext sc = request.getSession().getServletContext();
        WebApplicationContext wc = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
        appCtx = wc;
        CheckinService checkinSrv = (CheckinService)ctx.getBean("CustomCheckinService");

However, trying to obtain the bean using ClassPathXmlApplicationContext fails in various ways.

If I load the custom bean definition file itself I get the folllowing error:

code:

        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("alfresco/extension/custom-content-services-context.xml");
CheckinService checkinSrv = (CheckinService)ctx.getBean("CustomCheckinService");

error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'CustomCheckinService' defined in class path resource [alfresco/extension/custom-content-services-context.xml]: Can't resolve reference to bean 'ServiceRegistry' while setting property 'constructor argument'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'ServiceRegistry' is defined


OR

Code:

        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("alfresco/application-context.xml");
        CheckinService checkinSrv = (CheckinService)ctx.getBean("CustomCheckinService");

Error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ftsIndexerTrigger' defined in class path resource [alfresco/scheduled-jobs-context.xml]: Initialization of bean failed; nested exception is org.quartz.ObjectAlreadyExistsException: Unable to store Job with name: 'ftsIndexerJobDetail' and group: 'DEFAULT', because one already exists with this identification.


All wiki examples (on wiki.alfresco.com) show obtaining a custom bean via the ClassPathXmlApplicationContent (http://wiki.alfresco.com/wiki/Introducing_the_Alfresco_Java_Content_Repository_API), but it doesn't work (as shown above).  What is the correct way of obtaining a custom bean?

Thanks Dom

Outcomes