[size=24px]项目是maven搭建的,平时使用的是maven插件启动(用tomcat也可以成功启动),当服务器上部署项目的时候用的tomcat(7和8都试了),但是就是报以下错误,controller创建失败,service无法注入;[/size]
ERROR [localhost-startStop-1] - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ant_Services_Controller': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not   autowire field: private yq.manager.service.api.Ant_API_Services yq.manager.controller.Ant_Services_Controller.ant_API_Ser  vice; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [yq.  manager.service.api.Ant_API_Services] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(Aut          owiredAnnotationBeanPostProcessor.java:334)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapab          leBeanFactory.java:1202)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapab          leBeanFactory.java:537)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapable          BeanFactory.java:476)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistr          y.java:230)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBe          anFactory.java:762)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicat          ionContext.java:757)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
        at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java          :663)
        at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:629)
        at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:677)
        at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:548)
        at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:489)
        at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
        at javax.servlet.GenericServlet.init(GenericServlet.java:158)
        at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1269)
        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1182)
        at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1072)
        at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5361)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5659)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1015)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:991)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1127)
        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:2020)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
-------------------------------------------------------------------------------------------------------------------------------------------------------------
以下是controller的代码@Autowired(required=true)刚试过不好使,之前用的是@Autowired也不好使
@Controller
@RequestMapping("ant_services")
public class Ant_Services_Controller {
@Autowired(required=true)
private Ant_API_Services ant_API_Service;

/**
 * 分词
 * @param query
 */
@RequestMapping("/wordseg_Response")
@ResponseBody
 public  Ant_ServicesResult wordsegResponse(String query ){

Ant_ServicesResult result=null;
try {
result = ant_API_Service.wordSegService(query);
} catch (Exception e) {
e.printStackTrace();

}

return result;

}

解决方案 »

  1.   

    jar包是不少的,service的打成jar也加进来了,maven插件我删掉也试过了还是不好使
      

  2.   

    如果你WINDOS下运行没问题,一是检查下LINUX环境配置对没。二是看看你项目里有没有引入什么文件路径,因为LINUX目录结构也不同
      

  3.   

    我也碰到好多次,我都是mybatis的配置错误,导致实例化对象失败,然后引用就失败了。