无法在@ManagedBean中注入cxf服务

时间:2014-03-20 17:51:43

标签: java spring jsf primefaces cxf

我正在使用以下技术开展项目 -

  1. Spring 3.2
  2. CXF 2.2.12
  3. Primefaces 3.5
  4. 我创造了&成功发布了以下网络服务 -

    <bean id="loginService" class="com.cloudsym.service.login.LoginServiceImpl" />
    <jaxws:endpoint id="loginServiceWSId" implementor="#loginService" address="/iLoginService" />
    

    我已将客户定义如下 -

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"       
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:jaxws="http://cxf.apache.org/jaxws"
       xmlns:context="http://www.springframework.org/schema/context" 
       xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
        http://www.springframework.org/schema/jdbc
        http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
        http://cxf.apache.org/jaxws 
        http://cxf.apache.org/schemas/jaxws.xsd
        http://cxf.apache.org/transports/http/configuration
        http://cxf.apache.org/schemas/configuration/http-conf.xsd
        ">
    
    <http-conf:conduit name="*.http-conduit">
        <http-conf:client ReceiveTimeout="360000" />
    </http-conf:conduit>
    
    <bean id="clientWS" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean" abstract="true">
    </bean>
    
    <bean id="loginServiceClient" class="com.service.login.ILoginService" factory-bean="loginServiceFactory" factory-method="create"/>
    
    <bean id="loginServiceFactory" parent="clientWS">    
        <property name="serviceClass" value="com.service.login.ILoginService"/>
        <property name="address" value="http://localhost:9090/MYAPPWS/iLoginService"/>
    </bean>
    <bean id="loginServiceBean" class="com.controller.login.LoginController">
        <property name="loginService">
            <ref bean="loginServiceClient"/>
        </property>
    </bean> 
    

    相应的课程如下 -

    import java.io.Serializable;
    import javax.faces.bean.ManagedBean;
    import javax.faces.view.ViewScoped;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    import org.springframework.dao.DataAccessException;
    
    import com.service.login.ILoginService;
    import com.vo.login.LoginVo;
    
    @ManagedBean(name="loginBean")
    @ViewScoped
    public class LoginController implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    ILoginService loginService;
    
    public void fetchLoginDetails() {
        try {
            //String clientBeansPath = "classpath:com/resources/spring/client-beans.xml";
            //ClassPathXmlApplicationContext classPathXmlAppContext = new ClassPathXmlApplicationContext(clientBeansPath); 
            //classPathXmlAppContext.start();
            //ILoginService loginService = (ILoginService)classPathXmlAppContext.getBean("loginServiceClient");
            LoginVo loginVo = loginService.getLoginData("1");
            System.out.println("IN LOGINCONTROLLER");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    @Autowired
    public void setLoginService(ILoginService loginService) {
        this.loginService = loginService;
    }
    

    }

    当我从index.xhtml-

    调用上述方法时
    <p:commandButton value="Submit" action="#{loginBean.fetchLoginDetails}" ajax="false" />
    

    我收到如下错误 -

    java.lang.NullPointerException
    at com.controller.login.LoginController.fetchLoginDetails(LoginController.java:29)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:172)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Unknown Source)
    

    但是当我尝试使用ClassPathXmlApplicationContext(注释代码)时,我成功完成了服务调用并获得了所需的结果。

    我不确定为什么二传手注射不起作用.......

    由于

0 个答案:

没有答案