我的配置类有问题。每个日志的实际问题是:
> Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-05-10 10:47:47.622 ERROR 10728 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field queue in com.example.taskgenerator.Sender required a bean of type 'org.springframework.amqp.core.Queue' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.amqp.core.Queue' in your configuration.
我第一次在RabbitMQ和排队服务SDK中使用springboot。
package com.example.taskgenerator;
import org.springframework.amqp.core.Queue;
@Configuration
public class TaskGeneratorConfig {
@Bean
public Queue queue() {
return new Queue("simple-queue");
}
}
queue是Sender类的依赖项。
package com.example.taskgenerator;
import org.springframework.amqp.core.Queue;
@Component
public class Sender {
@Autowired
private Queue queue;
}
请帮忙。
编辑:
添加我的主要班级:
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Profile;
@SpringBootApplication
//@EnableScheduling
//@EnableAsync
public class FileDumpReaderApplication {
@Profile("usage_message")
@Bean
public CommandLineRunner usage() {
return new CommandLineRunner() {
@Override
public void run(String... args) throws Exception {
System.out.println("This app uses Spring profiles to control its behaviour.");
System.out.println("Sample usage : java -jar readerapp.jar --spring.profiles.active=hello_world,sender");
}
};
}
@Profile("!usage_message")
@Bean
public CommandLineRunner usageTwo() {
return new AppRunner();
}
public static void main(String[] args) {
SpringApplication.run(FileDumpReaderApplication.class, args);
}
}
和命令行运行程序类:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ConfigurableApplicationContext;
public class AppRunner implements CommandLineRunner {
@Autowired
private ConfigurableApplicationContext context;
@Autowired
private Sender sender;
@Override
public void run(String... args) throws Exception {
sender.send();
//context.close();
}
}
注意:所有类都在同一包中。
参考方案
扫描包裹-
@SpringBootApplication(scanBasePackages = {“ com.example.taskgenerator”}),并在AppRunner类上提供注解(@Component)。
您必须扫描您的程序包,以便在应用程序启动时它们成为ApplicationContext的一部分。
Spring Boot:java.time.Duration的默认序列化从字符串更改为数字 - java我们最近从Spring Boot 2.1.9升级到2.2.1,这导致我们的测试失败。调查导致结果,默认情况下java.time.Duration类型现在序列化为不同的序列。现在,我们将得到"PT15M",而不是在JSON消息中包含字符串"900.0"。 POJO定义如下所示@JsonProperty(required …
Java:“自动装配”继承与依赖注入 - javaImprove this question 我通常以常见的简单形式使用Spring框架: 控制器服务存储库通常,我会在CommonService类中放一个通用服务,并使所有其他服务扩展到类中。一个开发人员告诉我,最好在每个服务中插入CommonClass而不是使用继承。我的问题是,有一个方法比另一个更好吗? JVM或性能是否会受到另一个影响?更新资料Comm…
Spring Data Cassandra的事务管理 - java我正在使用Spring和Cassandra作为基础数据库。曾提到过弹簧伞项目“ spring data cassandra”。与休眠不同,在这里无法找到如何管理事务。如果您中的某些人已经合并,请共享要包含的事务管理器的详细信息。 参考方案 Cassandra不支持传统(ACID)的事务。在某些特殊情况下,可以通过一些构造来实现事务原子性,例如原子批处理(请参…
IntelliJ Spring MVC教程部署 - java我尝试了tutorial,当我尝试部署webapp(IntelliJ 13.1.4 Ultimate)时,出现了一个奇怪的错误,如下面的屏幕快照所示。解决此错误的方法是什么? org.jdom.input.JDOMParseException: Error on line 742: The content of elements must consist o…
Spring Boot-如何将application.yml属性定义为application.properties - java我目前正在尝试使用我的Spring Boot Web应用程序设置s3存储桶以添加/删除图像。我遵循的指南使用以下application.yml属性:amazonProperties: endpointUrl: https://s3.us-east-2.amazonaws.com accessKey: XXXXXXXXXXXXXXXXX secretKey: …