简体   繁体   中英

Context initialization failed, Bean creation exception

I have problem with above exception please give a guide line, here is my code:

//Calling Class


 package com.company.product.wsai.qb.ws.endpoint;

//Imports

@Endpoint
public class SendRequestXMLEndpoint implements SendRequestXMLManagementService {

    String strErrorMsg = "";

    // xml logging
    private static final String SEND_REQUEST_XML = "sendRequestXML";
    private static final String SEND_REQUEST_XML_RESPONSE = "sendRequestXMLResponse";

    @Autowired
    com.intuit.developer.ObjectFactory wsObjectFactory;

    @Autowired
    com.intuit.quickbooks.ObjectFactory qbObjectFactory;

    @Autowired
    TestService testService;

    @Autowired
    HistoryServiceImpl historyService;

    public static List<TaCategorySyncEntityDTO> travelAgentCategoryList ;   //Match to customerType in QB

    public static List<TravelAgentSyncEntityDTO> travelAgentList;   //Match to customer in QB

    public static List<VendorSyncEntityDTO> vendorList;   //Match to vendor in QB

    public static List<CurrencySyncEntityDTO> currencyList;   //Match to currency in QB

    public static List<ItemSyncEntityDTO> itemInventoryList; //Match to Item in QB

    public void doTravelAgent(){

        try{

        //Methods
        }catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void doTravelAgentCategory(){
            try{

            //Methods 

            }catch (Exception e) {
                e.printStackTrace();
            }
        }


    public void doVendor(){
        try{

          //Methods 
        }catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void doCurrency(){
        try{

        //Methods

        }catch (Exception e) {
            e.printStackTrace();
        }
    }

    @PayloadRoot(localPart = "sendRequestXML", namespace = XmlConfig.QB_WC_NAMESPACE)
    @ResponsePayload
    public SendRequestXMLResponse sendRequestXMLCommon(@RequestPayload SendRequestXML sendRequestXML) {
         doTravelAgentCategory();
         doTravelAgent();
         doVendor();
         doCurrency();
        String sessionTicket = sendRequestXML.getTicket();
        String strCompanyFileName = sendRequestXML.getStrCompanyFileName();

        // log request
        XmlLogManager.logSendRequestXMLEnpoint(sendRequestXML, SEND_REQUEST_XML, sessionTicket);

        SendRequestXMLResponse sendRequestXMLResponse = wsObjectFactory.createSendRequestXMLResponse();

        sendRequestXMLResponse.setSendRequestXMLResult(getSentXMLResult());

        // log response
        XmlLogManager.logSendRequestXMLEnpoint(sendRequestXMLResponse, SEND_REQUEST_XML_RESPONSE, sessionTicket);

        updateHistory();

        return sendRequestXMLResponse;

        }


    private String getSentXMLResult() {

        try{

            //Generate XML for quickBook

        } catch (JAXBException e) {
            e.printStackTrace();
        }
        return stringWriter.toString();
    }       


    public void updateHistory(){

        History taHistory = new History();
    Date dtReturn = StringToDate("19-06-2014");
        System.out.println(dtReturn);
        taHistory.setId(1L);
        taHistory.setEntityEvent('C');
        taHistory.setEntityType("TRAVELAGENT");
        taHistory.setEntityName("TEST");
        taHistory.setHotelCode("BBH");
        taHistory.setRecordTransfered('1');
        taHistory.setCreatedBy("TEST_USER");
        taHistory.setCreatedDate(dtReturn);
        taHistory.setVersion(1);

        try{
            historyService.saveHistory(taHistory);

        }catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static Date StringToDate(String strDate) {
        Date dtReturn = null;
         return dtReturn;
    }
}


//DAO Implementation class

    package com.company.product.wsai.qb.dao.historyDAO;

//imports

public class HistoryDAOImpl implements HistoryDAO {
    private SessionFactory sessionFactory;
    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    @Override
    public void saveHistory(History history) {
        sessionFactory.getCurrentSession().save(history);
    }
}

//Service implementation 

package com.company.product.wsai.qb.historyService;

//imports 

public class HistoryServiceImpl implements HistoryService {

@Autowired
private HistoryDAO historyDAO;


public void saveHistory(History history) {
    historyDAO.saveHistory(history);
 }
}

//Config xml

//remove upper part 

<context:component-scan base-package="com.jkcsworld.zhara.wsai.qb.historyService" />
    <context:component-scan base-package=" com.jkcsworld.zhara.wsai.qb.dao.historyDAO" />
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="configLocation">
            <value>/resources/hibernate.cfg.xml</value>
        </property>
     </bean>

     <bean id="historyDAO" class="com.jkcsworld.zhara.wsai.qb.dao.historyDAO.HistoryDAOImpl">
         <property name="sessionFactory" ref="sessionFactory"/>
     </bean>

</beans>

when i include autowired in calling class it's given an error in screen shot

错误

Your component scan should cover this package too

package com.company.product.wsai.qb.ws.endpoint;

Edit your config.xml as following, and one component-scan is enough.

<context:component-scan base-package="com.jkcsworld.zhara.wsai.qb" />

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="configLocation">
        <value>/resources/hibernate.cfg.xml</value>
    </property>
 </bean>

 <bean id="historyDAO" class="com.jkcsworld.zhara.wsai.qb.dao.historyDAO.HistoryDAOImpl">
     <property name="sessionFactory" ref="sessionFactory"/>
 </bean>

The problem is it can not find a matching bean for SendRequestXMLEndpoint.historyService

So mark your service as

package com.company.product.wsai.qb.historyService;
//imports

@Service // Mark it as service
public class HistoryServiceImpl implements HistoryService {

    @Autowired
    private HistoryDAO historyDAO;


    public void saveHistory(History history) {
        historyDAO.saveHistory(history);
    }
}
@Autowired
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

Modify your HistoryDAOImpl class to have above method.It should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM