我从JSF注释迁移到CDI。
我将@ManagedBean
更改为@Named
,并将SessionScoped包从javax.faces.bean
更改为javax.enterprise.context
。当我开始申请并尝试继续antek.xhtml
时,我遇到了以下异常:
Error Rendering View[/html/antek.xhtml] javax.faces.FacesException: Could not retrieve value of component with path : {Component-Path : [Class: org.ajax4jsf.component.AjaxViewRoot,ViewId: /html/antek.xhtml][Class: javax.faces.component.html.HtmlOutputText,Id: pojo]}
at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getValue(RendererUtils.java:347)
at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getStringValue(RendererUtils.java:295)
...
Caused by: javax.el.ELException: /html/antek.xhtml @15,63 value="#{antekBean.pojo}": Error reading 'pojo' on type com.antek.gui.test.AntekBean_$$_javassist_5
at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:76)
at javax.faces.component._DeltaStateHelper.eval(_DeltaStateHelper.java:243)
at javax.faces.component.UIOutput.getValue(UIOutput.java:71)
at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getValue(RendererUtils.java:343)
... 57 more
Caused by: javax.xml.ws.WebServiceException: javax.xml.bind.JAXBException: com.antek.core.dto.AntekDto is not known to this context
at org.apache.axis2.jaxws.ExceptionFactory.createWebServiceException(ExceptionFactory.java:175)
at org.apache.axis2.jaxws.ExceptionFactory.makeWebServiceException(ExceptionFactory.java:70)
at org.apache.axis2.jaxws.ExceptionFactory.makeWebServiceException(ExceptionFactory.java:128)
... 60 more
Caused by: javax.xml.bind.JAXBException: com.antek.core.dto.AntekDto is not known to this context
at com.ibm.jtc.jax.xml.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.java:642)
at com.ibm.jtc.jax.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.getBeanInfo(UnmarshallerImpl.java:568)
at com.ibm.jtc.jax.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:353)
... 83 more
当然在迁移之前一切都还可以。 我在WebSphere Application Server 8.0.0.7上工作。
我项目的源代码:
AntekDto.java
@XmlType // without that the same error is thrown
public class AntekDto implements Serializable {
private static final long serialVersionUID = 1L;
private String awesomeFiled;
public String getAwesomeFiled() {
return this.awesomeFiled;
}
public void setAwesomeFiled(final String awesomeFiled) {
this.awesomeFiled = awesomeFiled;
}
}
AntekWebService.java
@WebService(targetNamespace = "http://antek.com/core")
public interface AntekWebService {
@WebMethod(operationName = "getPojo")
@RequestWrapper(className = "GetPojoRequestWrapper")
@ResponseWrapper(className = "GetPojoResponseWrapper")
AntekDto getPojo();
}
AntekServiceImpl.java
@WebService(endpointInterface = "com.antek.testwebservice.AntekWebService", serviceName = "AntekService", targetNamespace = "http://antek.com/core")
public class AntekServiceImpl implements AntekWebService {
@Override
public AntekDto getPojo() {
final AntekDto antekDto = new AntekDto();
antekDto.setAwesomeFiled("some text for awesome field");
return antekDto;
}
}
AntekBean.java
@Named
@SessionScoped
public class AntekBean implements Serializable {
private static final long serialVersionUID = 2307667354352709172L;
@Produces
@WebServiceRef(name = AntekService.SERVICE_PORT_NAME, value = AntekService.class)
private transient AntekWebService antekWebService;
public String getPojo() {
return "<start>" + this.antekWebService.getPojo().getAwesomeFiled() + "<end>";
}
}
AntekService.java
@WebServiceClient(name = AntekService.SERVICE_NAME, targetNamespace = AntekService.NAMESPACE, wsdlLocation = AntekService.WSDL_LOCATION)
public class AntekService extends Service {
public static final String SERVICE_NAME = "AntekService";
public static final String SERVICE_PORT_NAME = SERVICE_NAME + "Port";
public static final String NAMESPACE = "http://antek.com/core";
public static final String WSDL_LOCATION = "http://localhost:" + WebServiceProperties.PORT_NUMBER
+ "/ApplicationClientWS/" + SERVICE_NAME + "/" + SERVICE_NAME + ".wsdl";
public AntekService(final URL wsdlLocation, final QName serviceName) {
super(wsdlLocation, serviceName);
}
@WebEndpoint(name = AntekService.SERVICE_PORT_NAME)
public final AntekWebService getAntekServicePort() {
return super.getPort(new QName(NAMESPACE, SERVICE_PORT_NAME), AntekWebService.class);
}
}
beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>
antek.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:t="http://myfaces.apache.org/tomahawk">
<head>
<title>cdi</title>
</head>
<body>
Object: <h:outputText id="pojo" value="#{antekBean.pojo}" />
</body>
</html>
有人可以解释一下为什么会抛出这个异常吗?