Spring + JAX-WS : ‘xxx’ is an interface, and JAXB can’t handle interfaces

Problem

Integrate Spring + JAX-WS, see web service below :


package com.mkyong.user.ws;
//imports...

@WebService()
public class PGUserWS {

    //DI via Spring
    private UserBo userBo;

    public UserBo getUserBo() {
        return userBo;
    }
    
    public void setUserBo(UserBo userBo) {
        this.userBo = userBo;
    }

    @WebMethod(operationName = "addUser")
    public boolean addUser(@WebParam(name = "userId")
    String userId, @WebParam(name = "User")
    User user) throws SOAPException {

        userBo.addUser(userId, user);
        return true;
    }

}

The “userBo” is DI via Spring XML bean configuration. But, when the service is generating the service’s files (via wsgen) for deployment, it hits “JAXB can’t handle interfaces” error message, see below :


Caused by: java.security.PrivilegedActionException: 
	com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 
            2 counts of IllegalAnnotationExceptions
	com.mkyong.user.bo.UserBo is an interface, and JAXB can't handle interfaces.
        this problem is related to the following location:
                at com.mkyong.user.bo.UserBo
                at private com.mkyong.user.bo.UserBo com.mkyong.user.ws.jaxws.SetUserBo.arg0
                at com.mkyonguser.ws.jaxws.SetUserBo
	com.mkyong.user.bo.UserBo does not have a no-arg default constructor.
        this problem is related to the following location:
                at com.mkyong.user.bo.UserBo
                at private com.mkyong.user.bo.UserBo com.mkyong.user.ws.jaxws.SetUserBo.arg0
                at com.mkyong.user.ws.jaxws.SetUserBo

Solution

See this unofficial JAXB guide to learn how to map interface in JAXB.

However, your case is different, it just doesn’t make sense to generate web service method for “userBo“, which is only require to Di via Spring, not publish to client.

To stop “wsgen” to generate web method for “userBo“, just annotate it with “@WebMethod(exclude = true)“, see below :


package com.mkyong.user.ws;

//imports...

@WebService()
public class PGUserWS {

    private UserBo userBo;

    @WebMethod(exclude = true)
    public UserBo getUserBo() {
        return userBo;
    }

    @WebMethod(exclude = true)
    public void setUserBo(UserBo userBo) {
        this.userBo = userBo;
    }

    @WebMethod(operationName = "addUser")
    public boolean addUser(@WebParam(name = "userId")
    String userId, @WebParam(name = "User")
    User user) throws SOAPException {

        userBo.addUser(userId, user);
        return true;
    }

}

Now, “wsgen” will ignore the “userBo” getter and setter methods.

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
14 Comment threads
3 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
15 Comment authors
Tati DanielleMarzieTaniaPauloVikas Recent comment authors
newest oldest most voted
Marzie
Guest
Marzie

Thanks a lot. It helped me a lot :)

Vikas
Guest
Vikas

You rock!!!

Jeff
Guest
Jeff

I’m starting to lose count of the number of times you’ve helped me. Thanks!

Gualtiero
Guest
Gualtiero

Problem fixed. Thanks.

Sudhir kumar
Guest
Sudhir kumar

I was facing the same issue. You gave the solution. Thank you very much Yong.

Gunjan Shah
Guest
Gunjan Shah

Thanks You .. I was facing the same problem. It resolved my problem.

Flam182
Guest
Flam182

Hello,

I add the annotation on my getter/setter :

  @WebMethod(exclude = true)

And i try to inject with spring :

 @Autowired
  private UserBo userBo;

But userBo is always null.
In applicationContext i have a “<context:component-scan" on my package.
I try to add this :

@WebService(serviceName = "PGUserWS ")
@Component("PGUserWS ")
Tania
Guest
Tania

i have the same issue, have you solved??

Adam
Guest
Adam

Thank you, just solved my problem!

vajpai
Guest
vajpai

Excellent. It help lot.

Ben
Guest
Ben

Thanks! Exactly the problem I was having with a Spring-injected LdapTemplate. Added the “exclude” argument to the WebMethod annotation and my errors disappeared.

trackback
JAX-WS Tutorials

[…] Spring + jax-ws : ‘xxx’ is an interface, and JAXB can’t handle interfaces […]

passer_by
Guest
passer_by

thanks. it works!

Aditi
Guest
Aditi

Thanks a lot…really helpfull..it worked

trackback
Spring + JAX-WS : ‘xxx’ is an interface, and JAXB can’t handle interfaces

[…]   //DI via Spring private UserBo userBo;   public UserBo getUserBo() {… [full post] mkyong Mkyong Dot Com jax-wsspring 0 0 0 0 0 […]

Paulo
Guest
Paulo

You are the JBoss :)

Tati Danielle
Guest
Tati Danielle

You are the Wildfly!