Jax-ws, spring and SpringBeanAutowiringSupport

although in my @Webservice class I am extending SpringBeanAutowiringSupport, auto-installation just doesn't work for Spring 2.5, tomcat6.

nothing is entered.

I tested those beans autowiring in the main method using classpathcontext, everything is injected fine. But not for the jax-ws endpoint.

Do you have any ideas?

+3
source share
4 answers

I assume that you are using this configuration item:

<context:annotation-config />

But to enable @Endpoint annotation support, you must add this element:

<context:component-scan base-package="" />
+1
source

. , Spring autowire beans @WebService ( , ).

:

org.springframework.beans.factory.config.AutowireCapableBeanFactory.class @Autowired beans (, @Service, @Repository ..).

:

  • @Resource WebServiceContext

    @Resource
    private WebServiceContext context;  
    
  • bean

    MyDAO myDAO = null;
    ServletContext servletContext = (ServletContext) context
        .getMessageContext().get("javax.xml.ws.servlet.context");
    WebApplicationContext webApplicationContext = WebApplicationContextUtils
        .getRequiredWebApplicationContext(servletContext);
    myDAO = (MyDAO) webApplicationContext
        .getAutowireCapableBeanFactory().getBean("myDAO");
    

    MyDAO :

    @Service
    @Qualifier("myDAO")    
    @Transactional
    public class MyDAO {
        private HibernateTemplate hibernateTemplate;
    
        @Required
        @Autowired
        public void setSessionFactory(SessionFactory sessionFactory) {
            this.hibernateTemplate = new HibernateTemplate(sessionFactory);
        }
    
        public MyInfo getMyInfo(Long id){
            return this.hibernateTemplate.get(MyInfo.class, id);
        }
    
        //...
    }
    
  • MyDAO @WebMethod.

+9

, , . , web.xml. ContextLoaderListener , WSServletContextListener .

+4
source

It would be better if you would use some reference implementation such as Metro, Axis2, apache-cxf to easily configure such an endpoint in a web service.

0
source

Source: https://habr.com/ru/post/1747834/


All Articles