Почему JAXB пытается связать ApplicationContext в Spring? - PullRequest
3 голосов
/ 23 июня 2011

Я работаю над приложением Spring, которое предоставляет веб-сервис JAX-WS.Реализация веб-службы зависит от какого-то подпружиненного объекта в моем сервисном слое и выглядит следующим образом:

@WebService
public class BlahService {
    ...
    public void setFooService(FooService f) {
        ...
    }
}

, где FooService определяется в контексте приложения и внедряется в BlahService во время веб-приложения.запускать.FooService со своей стороны зависит от BarService, который снова определяется в контексте приложения и внедряется при запуске, следовательно, BlahService выше транзитивно зависит от BarService.

Вот он, хитрая часть.BarService реализует ApplicationContextAware, поэтому его код напоминает обычный

public class BazService implements ApplicationContextAware {

    private ApplicationContext applicationContext;

    public final void setApplicationContext(ApplicationContext ctx) {
        this.applicationContext = ctx;
    }
    ...
}

Теперь, если я не аннотирую setApplicationContext с @XmlTransient, приложение не запустится, жалуясь на applicationContext как интерфейс ипоэтому невозможно привязать к JAXB.Что мне не хватает?Почему JAXB пытается связать ApplicationContext с XML?

Stacktrace или этого не произошло

####<Jun 22, 2011 7:28:31 PM CEST> <Info> <ServletContext-/MyApp> <duck> <myserver> <[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1308763711259> <BEA-000000> <Initializing Spring root WebApplicationContext> 
####<Jun 22, 2011 7:28:32 PM CEST> <Error> <HTTP> <duck> <myserver> <[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1308763712595> <BEA-101216> <Servlet: "myApp-jax-ws-servlet" failed to preload on startup in Web application: "MyApp.war".
javax.xml.ws.WebServiceException: Unable to create JAXBContext
    at com.sun.xml.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:164)
    at com.sun.xml.ws.model.AbstractSEIModelImpl.postProcess(AbstractSEIModelImpl.java:94)
    at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:281)
    at com.sun.xml.ws.server.EndpointFactory.createSEIModel(EndpointFactory.java:363)
    at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:202)
    at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:496)
    at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:539)
    at weblogic.wsee.jaxws.JAXWSDeployedServlet.getEndpoint(JAXWSDeployedServlet.java:183)
    at weblogic.wsee.jaxws.JAXWSServlet.registerEndpoint(JAXWSServlet.java:135)
    at weblogic.wsee.jaxws.JAXWSServlet.init(JAXWSServlet.java:64)
    at weblogic.wsee.jaxws.JAXWSDeployedServlet.init(JAXWSDeployedServlet.java:54)
    at javax.servlet.GenericServlet.init(GenericServlet.java:241)

    ... lots of weblogic stuff ...

Caused By: java.security.PrivilegedActionException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
org.springframework.context.ApplicationContext is an interface, and JAXB can't handle interfaces.
    this problem is related to the following location:
        at org.springframework.context.ApplicationContext
        at public final org.springframework.context.ApplicationContext my.package.myApp.service.db.DBManager.getApplicationContext()
        at my.package.myApp.service.db.DBManager
        at public my.package.myApp.service.db.DBManager my.package.myApp.service.sso.SSOInterface.getDBManager()
        at my.package.myApp.service.sso.SSOInterface
        at public my.package.myApp.service.sso.SSOInterface my.package.myApp.ws.inBound.jaxws.SetSsoInterface.arg0
        at my.package.myApp.ws.inBound.jaxws.SetSsoInterface
org.springframework.context.ApplicationContext does not have a no-arg default constructor.
    this problem is related to the following location:
        at org.springframework.context.ApplicationContext
        at public final org.springframework.context.ApplicationContext my.package.myApp.service.db.DBManager.getApplicationContext()
        at my.package.myApp.service.db.DBManager
        at public my.package.myApp.service.db.DBManager my.package.myApp.service.sso.SSOInterface.getDBManager()
        at my.package.myApp.service.sso.SSOInterface
        at public my.package.myApp.service.sso.SSOInterface my.package.myApp.ws.inBound.jaxws.SetSsoInterface.arg0
        at my.package.myApp.ws.inBound.jaxws.SetSsoInterface

    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.xml.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:151)
    at com.sun.xml.ws.model.AbstractSEIModelImpl.postProcess(AbstractSEIModelImpl.java:94)
    at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:281)
    at com.sun.xml.ws.server.EndpointFactory.createSEIModel(EndpointFactory.java:363)
    at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:202)
    at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:496)
    at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:539)
    at weblogic.wsee.jaxws.JAXWSDeployedServlet.getEndpoint(JAXWSDeployedServlet.java:183)
    at weblogic.wsee.jaxws.JAXWSServlet.registerEndpoint(JAXWSServlet.java:135)
    at weblogic.wsee.jaxws.JAXWSServlet.init(JAXWSServlet.java:64)
    at weblogic.wsee.jaxws.JAXWSDeployedServlet.init(JAXWSDeployedServlet.java:54)
    at javax.servlet.GenericServlet.init(GenericServlet.java:241)

        ... lots of weblogic stuff again ...

Caused By: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
org.springframework.context.ApplicationContext is an interface, and JAXB can't handle interfaces.
    this problem is related to the following location:
        at org.springframework.context.ApplicationContext
        at public final org.springframework.context.ApplicationContext my.package.myApp.service.db.DBManager.getApplicationContext()
        at my.package.myApp.service.db.DBManager
        at public my.package.myApp.service.db.DBManager my.package.myApp.service.sso.SSOInterface.getDBManager()
        at my.package.myApp.service.sso.SSOInterface
        at public my.package.myApp.service.sso.SSOInterface my.package.myApp.ws.inBound.jaxws.SetSsoInterface.arg0
        at my.package.myApp.ws.inBound.jaxws.SetSsoInterface
org.springframework.context.ApplicationContext does not have a no-arg default constructor.
    this problem is related to the following location:
        at org.springframework.context.ApplicationContext
        at public final org.springframework.context.ApplicationContext my.package.myApp.service.db.DBManager.getApplicationContext()
        at my.package.myApp.service.db.DBManager
        at public my.package.myApp.service.db.DBManager my.package.myApp.service.sso.SSOInterface.getDBManager()
        at my.package.myApp.service.sso.SSOInterface
        at public my.package.myApp.service.sso.SSOInterface my.package.myApp.ws.inBound.jaxws.SetSsoInterface.arg0
        at my.package.myApp.ws.inBound.jaxws.SetSsoInterface

    at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:102)
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:478)
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:308)
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1149)
    at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:169)
    at com.sun.xml.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:160)
    at com.sun.xml.ws.developer.JAXBContextFactory$1.createJAXBContext(JAXBContextFactory.java:74)
    at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:159)
    at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:151)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.xml.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:151)
    at com.sun.xml.ws.model.AbstractSEIModelImpl.postProcess(AbstractSEIModelImpl.java:94)
    at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:281)
    at com.sun.xml.ws.server.EndpointFactory.createSEIModel(EndpointFactory.java:363)
    at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:202)
    at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:496)
    at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:539)
    at weblogic.wsee.jaxws.JAXWSDeployedServlet.getEndpoint(JAXWSDeployedServlet.java:183)
    at weblogic.wsee.jaxws.JAXWSServlet.registerEndpoint(JAXWSServlet.java:135)
    at weblogic.wsee.jaxws.JAXWSServlet.init(JAXWSServlet.java:64)
    at weblogic.wsee.jaxws.JAXWSDeployedServlet.init(JAXWSDeployedServlet.java:54)
    at javax.servlet.GenericServlet.init(GenericServlet.java:241)

    ... more weblogic stuff ...

Ответы [ 3 ]

3 голосов
/ 23 июня 2011

По умолчанию реализации JAXB отобразят все открытые поля и свойства. Вы можете использовать аннотацию @XmlTransient, чтобы предотвратить сопоставление свойств:

@XmlTransient
public void setFooService(FooService f) {
    ...
}
0 голосов
/ 22 июля 2011

Другой вариант - внедрить fooService через конструктор arg

BlahService {... public BlashService (FooService f) {this.fooService = f;}

0 голосов
/ 23 июня 2011

JAXB берет все свойства bean-компонента (доступ к ним получают и получают) и пытается его маршалировать или демаршировать.

Одна вещь, которую я не понимаю - вы пытаетесь организовать BazService?Разве это не одиночный сервис?

...