Announcement Announcement Module
Collapse
No announcement yet.
How did AnnotationConfigWebApplicationContext setup the rootBeanDefinition ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How did AnnotationConfigWebApplicationContext setup the rootBeanDefinition ?

    Hi, Spring experts and Forum Friends,

    I've issue confused me , How many steps need to be made sure when change XML based applicationContext to Annotation-based applicationContext.

    When I do this things , I've successfully changed applicationContext configuration of spring-ws, by overwrite the method
    "protected WebApplicationContext createWebApplicationContext(ApplicationContext parent)".
    In it, I just copy all of the statements of the method in super Class MessageDispatcherServlet, and add this
    "
    Code:
    ((AnnotationConfigWebApplicationContext)wac).register(MyOwnConfiguration.class);
    " before was.refresh(), of course "
    Code:
    this.setContextClass(AnnotationConfigWebApplicationContext.class);
    " is required in the constructor. It's really can do bean Injection after I did this. Then I read the "web-services-2.0.xsd" file to configur some ws required beans in MyOwConfiguration.class, it also worked. Then I'm sure I did successfully in spring-ws.

    But while I did the same operation in apache-cxf , It's failed, in the same MyOwnConfiguration.class, in it, I found the
    @Bean BeanType beanName(){} , although which can prepared beans, but after it was called, the @Resource public void setBean(BeanType bean) did not execute. And deeply, I found in AbstractBeanFactory, the statements below are executed in wrong case:
    Code:
    final RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);
    			checkMergedBeanDefinition(mbd, beanName, args);
    The gotten mbd is wrong , because it bring a Root[null] info. But the check statements could execute without any exception throwout.


    So Here I consult every friend , do you have any idea on config rootBeanDefinition for AnnotationConfigWebApplicationContext?
    Last edited by palmtale; Feb 1st, 2013, 03:53 AM. Reason: Add code tag

  • #2
    One question... Why on earth are you doing that, why aren't you using springs own mechanisms instead of hacking your own together.. Specify the contextConfigClass property and simply use the contextConfigLocation to specify which classes to load.

    Comment


    • #3
      Sorry, What did you mean? Also specified stuff in web.xml?
      I did just want to know why it can go well in spring-ws MessageDispatcherServlet, but cannot go well in apache-cxf CXFServlet.
      These 2 Servlets both reconfigurated XmlApplicationContext as the self-def sub-applicationContext,
      I just want to change it to AnnotationConfigWebApplicationContext, so overwrite the createApplicationContext(parentAppContext) method.
      Last edited by palmtale; Feb 1st, 2013, 04:02 AM. Reason: Update

      Comment


      • #4
        Why are you overriding those methods just to add a configuration class, that can all be done by configuration instead of hacking together your own servlet.

        Comment


        • #5
          Thanks, you mean set initParam to point the self-def configedBeans.xml? But I don't want to setup any configuration.xml, Just use one properties file to arrange configuration.

          Comment


          • #6
            Well, I've found the cause by checking tomcat console log, It's necessary to execute the bean's init-method. So when init a new EndpointImpl(org.apache.cxf.jaxws.EndpointImpl), should call it's init method publish(). For my case, 2 ways:
            Code:
            @Bean(initMethod="publish")
            	EndpointImpl commonEndpoint(){
            		EndpointImpl cxfEndpoint = new JAXWS22SpringEndpointImpl(bus,new CXFCommonEndpoint());
            //		cxfEndpoint.publish();
            		return cxfEndpoint;
            	}
            1, Add initMethod property of Bean Annotation,
            2, The method annotated by @Bean itself, is a initial progress of the bean, so just call the method in it.

            Comment

            Working...
            X