简体   繁体   中英

After new Controller created i'm getting “Injection of autowired dependencies failed” in Spring MVC , Hibernate

I have added a new controller in my spring mvc project and added all annotations as below ...but here while running the project i'm getting 404 exception and in the console i'm getting exception as below ...I'm confused to figure out the issue...

here is my controller:

@Controller
@RequestMapping("/escProjectProgStatusController")
public class ESCProjectProgStatusController {
    @Autowired
    ESCProjectProgStatusService escProjectProgStatusService;   
@RequestMapping(value = "/fetchUnitNameDropDown")
    public @ResponseBody String fetchUnitNameDropDown(HttpServletRequest request){
        String strUnitNames = "";
        String strProjectId = request.getParameter("projectId")==null?"":request.getParameter("projectId");
        try {
            strUnitNames = escProjectProgStatusService.fetchUnitNameFromProjectId(strProjectId);
        } catch (Exception e) {  
            //logger.error(e);
            throw e;
        }
        return strUnitNames.toString();
    }
}

service Impl:

@Service("escProjectProgStatusServices")
@Transactional
public class ESCProjectProgStatusServiceImpl implements ESCProjectProgStatusService {

    @Autowired
    ESCProjectProgStatusDao escProjectProgStatusDao;
@Override
    public String fetchUnitNameFromProjectId(String strProjectId){
        JSONArray jsonArr = new JSONArray();
        JSONObject jsonObj = null;
        List<ProjectUnit> listProjectUnit = null;
        try{
            listProjectUnit = (List<ProjectUnit>)escProjectProgStatusDao.fetchUnitNameFromProjectId(strProjectId);
            if(listProjectUnit!=null){
                for(ProjectUnit projectUnit :listProjectUnit){
                    jsonObj = new JSONObject();
                    jsonObj.put("unitType", projectUnit.getUnitType());
                    jsonObj.put("unitName", projectUnit.getUnitName());
                    jsonArr.add(jsonObj);
                }
            }
        }catch(Exception e){
            //logger.error(e);
        }
        return jsonArr.toString();
    }
}

Dao Impl:

@Repository("escProjectProgStatusDao")
public class ESCProjectProgStatusDaoImpl implements ESCProjectProgStatusDao {
    @Autowired
    private SessionFactory sessionFactory;
@Override
    public List<ProjectUnit> fetchUnitNameFromProjectId(String strProjectId){
        List<ProjectUnit> listProjectUnit = null;
        try {
            Session session = sessionFactory.getCurrentSession();
            Criteria criteria = session.createCriteria(ProjectUnit.class);
            criteria.add(Restrictions.eq("merchantProductID", strProjectId));
            listProjectUnit=criteria.list();
        }catch(Exception e){
            //logger.error(e);
        }
        return listProjectUnit;
    }
}

Exception and Stack Trace:

 SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ESCProjectProgStatusController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.interland.b2b.service.ESCProjectProgStatusService com.interland.b2b.controller.ESCProjectProgStatusController.escProjectProgStatusService; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.lang.String' to required type 'com.interland.b2b.service.ESCProjectProgStatusService'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.interland.b2b.service.ESCProjectProgStatusService]: no matching editors or conversion strategy found
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1208)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:759)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:434)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
    Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.interland.b2b.service.ESCProjectProgStatusService com.interland.b2b.controller.ESCProjectProgStatusController.escProjectProgStatusService; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.lang.String' to required type 'com.interland.b2b.service.ESCProjectProgStatusService'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.interland.b2b.service.ESCProjectProgStatusService]: no matching editors or conversion strategy found
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
        at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
        ... 22 more
    Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.lang.String' to required type 'com.interland.b2b.service.ESCProjectProgStatusService'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.interland.b2b.service.ESCProjectProgStatusService]: no matching editors or conversion strategy found
        at org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:74)
        at org.springframework.beans.TypeConverterSupport.convertIfNecessary(TypeConverterSupport.java:54)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:961)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
        ... 24 more
    Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.interland.b2b.service.ESCProjectProgStatusService]: no matching editors or conversion strategy found
        at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:287)
        at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:124)
        at org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:61)
        ... 28 more

Can anyone please help me to get rid of this problem..Many thanks in advance....

In ESCProjectProgStatusServiceImpl class remove the String parameter of @Service annotation:

before:

@Service("escProjectProgStatusServices")

after:

@Service

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