gpt4 book ai didi

java - 当我使用 spring boot 运行项目时。它运行良好。但是当我将它部署到tomcat中时。我收到低于书面的异常

转载 作者:行者123 更新时间:2023-12-01 11:45:46 25 4
gpt4 key购买 nike

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 boot 的情况下,我在类级别使用此注释。

@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);
}

当我使用上面的主要方法运行我的应用程序时。它运行良好。

但是当我删除此代码并尝试使用具有相同应用程序上下文的 web.xml 运行此应用程序时。它给出了错误。请帮忙!

最佳答案

在 Spring Boot 中运行时,Spring 可以毫无问题地找到 CPPApplication 注释,但是当部署为 war 时,您需要在扩展 SpringBootServletInitializer 的类上添加这些注释。

这里有详细描述:http://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html

关于java - 当我使用 spring boot 运行项目时。它运行良好。但是当我将它部署到tomcat中时。我收到低于书面的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29145348/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com