Java Springboot无法通过自动连线注释初始化和注入第三方bean

Java Springboot无法通过自动连线注释初始化和注入第三方bean,java,spring-boot,rabbitmq,javabeans,Java,Spring Boot,Rabbitmq,Javabeans,我的配置类有问题。根据日志,实际问题是: > 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 : *******

我的配置类有问题。根据日志,实际问题是:

> 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.
我第一次将springboot与RabbitMQ一起使用,这是一个队列服务sdk

    package com.example.taskgenerator;
    import org.springframework.amqp.core.Queue;
    @Configuration
    public class TaskGeneratorConfig {
        @Bean
        public Queue queue() {
            return new Queue("simple-queue");
        }
    }
队列是发送方类的依赖项

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 starter web依赖项,并且您的主类在哪里?发布您的主类。在此处查看如何使用RabbitMQ设置spring boot谢谢您的回复。这是我的主要课程:@Adya它不是一个web应用程序。即使不是web项目,我也应该添加此依赖项吗?请澄清。但之前它运行良好。