为什么我的Spring @Autowired不能在这个Web服务中工作

时间:2017-04-27 14:17:02

标签: java spring nullpointerexception null autowired

我使用JAX-WS创建一个Web服务但是我不能使用@Autowired注入一个Bean

我做了很多事但没有成功。

任何人都有一些想法可以帮助我解决这个问题吗?

非常感谢。

IndicadoresBSTSWebServiceImpl:

package com.santander.portalcio.ws;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.jws.WebService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;

import com.santander.portalcio.backend.entities.IncidentType;
import                 
com.santander.portalcio.backend.services.bsts.indicators.BSIndicatorVO;
import com.santander. 
portalcio.backend.services.bsts.indicators.BSTSIndicatorsFilterVO;
import 
com.santander.portalcio.backend.services.bsts.indicators.EntityIndicatorVO;
import 

com.santander.
portalcio.backend.services.bsts.indicators.FunctionalityIndicatorVO;
import com.santander.
portalcio.backend.services.bsts.indicators.TSIndicatorVO;
import com.santander.
portalcio.ui.managedbean.home.HomeIndicadoresReportService;

@Service
@WebService(endpointInterface =         
"com.santander.
portalcio.ws.IndicadoresBSTSWebServiceInterface")
public class IndicadoresBSTSWebServiceImpl extends                     
SpringBeanAutowiringSupport 
implements IndicadoresBSTSWebServiceInterface {


@PostConstruct
public void init() {
    SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
}

@Autowired
private HomeIndicadoresReportService homeIndicadoresReportService;

private List<EntityIndicatorVO> resultMesAtual;

private BSTSIndicatorsFilterVO filter = new BSTSIndicatorsFilterVO();

private EntityIndicatorVO selectedEntity = new EntityIndicatorVO();
private BSIndicatorVO selectedBS = new BSIndicatorVO();
private TSIndicatorVO selectedTS = new TSIndicatorVO();
private FunctionalityIndicatorVO selectedFunctionality = new     
FunctionalityIndicatorVO();


@Override
public ListaWS teste() {
    filter.setStart(new Date("01/01/2016"));
    filter.setEnd(new Date("01/31/2016"));
    IncidentType[] tipo = { IncidentType.BATCH, IncidentType.ONLINE };
    filter.setTypeList(tipo);
    resultMesAtual = new ArrayList<EntityIndicatorVO>();

    homeIndicadoresReportService.buildValuesToGraph(resultMesAtual, 
    selectedEntity, selectedBS, selectedTS,
            selectedFunctionality, filter, false);


    return new ListaWS(resultMesAtual);
    }

}

IndicadoresBSTSWebServiceInterface:

package com.santander.portalcio.ws;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.ParameterStyle;
import javax.jws.soap.SOAPBinding.Style;

@WebService
@SOAPBinding(style = Style.RPC, parameterStyle = ParameterStyle.WRAPPED)
public interface IndicadoresBSTSWebServiceInterface {

@WebMethod
ListaWS teste();

}

web.XML:

<listener>
    <listener-class>
        com.sun.xml.ws.transport.http.servlet.WSServletContextListener
    </listener-class>
</listener>
<servlet>
    <servlet-name>indicadoresBSTS</servlet-name>
    <servlet-class>
        com.sun.xml.ws.transport.http.servlet.WSServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>indicadoresBSTS</servlet-name>
    <url-pattern>/indicadoresBSTS</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>30</session-timeout>
</session-config>

HomeIndicadoresReportService:

package com.santander.portalcio.ui.managedbean.home;

import java.io.Serializable;
import java.util.List;

import     com.santander.
portalcio.backend.services.bsts.indicators.BSIndicatorVO;
import com.santander.
portalcio.backend.services.bsts.indicators.BSTSIndicatorsFilterVO;
import com.santander.
portalcio.backend.services.bsts.indicators.EntityIndicatorVO;
import com.santander.
portalcio.backend.services.bsts.indicators.FunctionalityIndicatorVO;
import com.santander.
portalcio.backend.services.bsts.indicators.TSIndicatorVO;

public interface HomeIndicadoresReportService extends Serializable {

public void selectAndBuildEntityBsTsFunc
(List<EntityIndicatorVO> resultAux,     BSTSIndicatorsFilterVO filter);

public void selectcompFuncInc
(List<EntityIndicatorVO> resultAux, EntityIndicatorVO selectedEntity,
        BSIndicatorVO selectedBS, 
TSIndicatorVO selectedTS, FunctionalityIndicatorVO selectedFunctionality,
        BSTSIndicatorsFilterVO filter, boolean isIndicatorsBSTS);

public void selectTotaoInc
(List<EntityIndicatorVO> resultAux, EntityIndicatorVO selectedEntity,
        BSIndicatorVO selectedBS, 
TSIndicatorVO selectedTS,         
FunctionalityIndicatorVO     selectedFunctionality, 
BSTSIndicatorsFilterVO filter);

public void buildValuesToGraph
(List<EntityIndicatorVO> resultMes,     EntityIndicatorVO selectedEntity,
        BSIndicatorVO selectedBS, 
TSIndicatorVO selectedTS, FunctionalityIndicatorVO selectedFunctionality,
        BSTSIndicatorsFilterVO filter, boolean isIndicatorsBSTS);

}

HomeIndicadoresReportServiceBean:

package com.santander.portalcio.ui.managedbean.home;
@Repository
@Transactional(propagation = 
Propagation.REQUIRED, rollbackFor =     Exception.class)
public class HomeIndicadoresReportServiceBean 
implements HomeIndicadoresReportService {

private static final long serialVersionUID = 6513587371275348695L;

@PersistenceContext
private EntityManager em;

@Autowired
private UnavailabilityValidationHelper unavailabilityHelper;

@Autowired
private FunctionalityAvailableService functionalityAvailableService;

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

DecimalFormat df = new DecimalFormat("#,###,###");
DecimalFormat dfHour = new DecimalFormat("00");

@Override
public void buildValuesToGraph(List<EntityIndicatorVO> 
resultMes, EntityIndicatorVO selectedEntity,
        BSIndicatorVO selectedBS, TSIndicatorVO 
selectedTS, FunctionalityIndicatorVO selectedFunctionality,
        BSTSIndicatorsFilterVO filter, boolean isIndicatorsBSTS) {

    selectAndBuildEntityBsTsFunc(resultMes, filter);

    selectcompFuncInc(resultMes, selectedEntity, 
selectedBS, selectedTS, selectedFunctionality, filter,
            isIndicatorsBSTS);

1 个答案:

答案 0 :(得分:0)

当您尝试自动装配HomeIndicadoresReportService时,似乎您没有将其配置为Spring bean。您可以使用@Service注释HomeIndicadoresReportService类,在应用程序上下文文件中创建XML配置条目,或者在Java配置类中为此创建@Bean配置方法(取决于您如何配置Spring上下文)。 p>