简体   繁体   English

创建新的Controller之后,我在Spring MVC中遇到“自动连接依赖项注入失败”的问题,Hibernate

[英]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... 我在我的spring mvc项目中添加了一个新的控制器并添加了所有注释,如下所示……但是在运行项目时,我遇到了404异常,而在控制台中却出现了如下异常……我很困惑找出问题...

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: 服务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: 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: ESCProjectProgStatusServiceImpl类中,删除@Service注释的String参数:

before: 之前:

@Service("escProjectProgStatusServices")

after: 后:

@Service

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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