[英]After new Controller created i'm getting “Injection of autowired dependencies failed” in Spring MVC , Hibernate
我在我的spring mvc項目中添加了一個新的控制器並添加了所有注釋,如下所示……但是在運行項目時,我遇到了404異常,而在控制台中卻出現了如下異常……我很困惑找出問題...
這是我的控制器:
@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();
}
}
服務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;
}
}
異常和堆棧跟蹤:
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
任何人都可以幫助我擺脫這個問題。。在此先感謝...。
在ESCProjectProgStatusServiceImpl
類中,刪除@Service
注釋的String參數:
之前:
@Service("escProjectProgStatusServices")
后:
@Service
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.