How to troubleshoot spring injection as empty in the WebService of Xfire publications

Source: Internet
Author: User
Tags empty wsdl

The injection of empty in the spring framework is a headache, and it is easier to find the cause of the problem when WebService and the spring framework fit.

In the SSO system encountered this problem, in the service implementation class to inject Ibatis database operations Mapper has been empty, and finally found that the reason is Xfire and spring when used in conjunction with the normal use of Xfire configuration different

Xfire can quickly release webservice, which typically requires only a few steps below.

1. Create service Interfaces and implementation classes

such as Ssomethodsservices and Ssomethodsimpl.

Injection in the implementation class including the Spring annotation form

@Autowired

Private Accountmapper Accountmapper;

2. Add Xfire configuration in Web.xml

<servlet>   
    <servlet-name>XFireServlet</servlet-name>   
    <display-name>xfire servlet </display-name>   
    <servlet-class>   
        org.codehaus.xfire.transport.http.XFireConfigurableServlet   
    </servlet-class>   
  </servlet>   
       
  <servlet-mapping>   
    <servlet-name> xfireservlet</servlet-name>   
    <url-pattern>/servlet/XFireServlet/*</url-pattern>   
  < /servlet-mapping>   
       
  <servlet-mapping>   
    <servlet-name>XFireServlet</servlet-name>   
    <url-pattern>/services/*</url-pattern>   
  </servlet-mapping>

3. Create a directory under the Classpath directory Meta-inf>xifre->services.xml

Configuring services in the Services.xml file

<?xml version= "1.0" encoding= "UTF-8"?>     
<beans>     
<service xmlns= "http://xfire.codehaus.org/ config/1.0 ">     
    <name>SSOMethodsServices</name>     
    <serviceClass> Com.test.sso.ssomethodsservices</serviceclass>     
    <implementationClass> com.test.sso.impl.ssomethodsimpl</implementationclass>     
</service>         
</beans>

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/Java/

In this way, you can see the published WebService in the browser input ip:port/projectname/services, and click WSDL to see the WSDL file.

However, the SOAPUI was used to test and found that the injected accountmapper was empty. There is a problem.

Attempts to direct manual injection, add @component annotation and add packet scanning and other methods can not be injected, and later found that its real xfire example directory with spring example, the use of different configuration methods, this way proved to be effective.

The main differences are:

1. Servlet class uses Org.codehaus.xfire.spring.XFireSpringServlet Rather than Org.codehaus.xfire.transport.http.XFireConfigurableServlet. This is the most critical point.

2. Add Xfire-servlet.xml to Web.xml Context-param using a xfire-servlet.xml profile configuration service instead of Services.xml.

3. Add the bean of the WebService implementation class to the Applicationcontext.xml.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.