Caused by: org.springframework.beans.factory.BeanCreationException:
Could not autowire field: private org.springframework.boot.actuate.metrics.GaugeService com.snapdeal.cpp.metrics.SDBootMetricPublisher.gaugeService;
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type [org.springframework.boot.actuate.metrics.GaugeService] 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)}
注意:在Spring启动的情况下,我在类级别使用此注释。
@SpringBootApplication
@EnableScheduling
@EnableAspectJAutoProxy
@ImportResource("classpath:spring/application-context*.xml")
@ComponentScan({"com.cpp.*"})
public class CPPApplication{
public static void main(String[] args) {
SpringApplication application = new SpringApplication(CPPApplication.class);
application.setShowBanner(false);
application.run(args);
}
当我使用上面的main方法运行我的应用程序时。它工作正常。
但是当我删除此代码并尝试使用具有相同应用程序上下文的web.xml运行此应用程序时。它给出了错误。请帮忙!
答案 0 :(得分:1)
在Spring Boot中运行时,Spring在查找CPPApplication注释时没有问题,但是当部署为战争时,您需要在扩展SpringBootServletInitializer的类上添加这些注释。
此处详细说明:http://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html