Spring, Gradle编译org.springframework.boot.autoconfigure错误



我想用Spring框架写我自己的IM。我读了这个:

Getting Started -使用RabbitMQ发送消息

当我编译下面的代码时,我得到这个错误信息:http://pastebin.com/7gNJBAE2

如有任何帮助或建议,我将不胜感激。

我用:Windows 8.1,Java 8,NetBeans 8.0.2。Gradle 2.5

Receiver.java

package hello;
    import java.util.concurrent.CountDownLatch;
    public class Receiver {
        private CountDownLatch latch = new CountDownLatch(1);
        public void receiveMessage(String message) {
            System.out.println("Received <" + message + ">");
            latch.countDown();
        }
        public CountDownLatch getLatch() {
            return latch;
        }
    }

Application.java

package hello;
import java.util.concurrent.TimeUnit;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class Application implements CommandLineRunner {
    final static String queueName = "spring-boot";
    @Autowired
    AnnotationConfigApplicationContext context;
    @Autowired
    RabbitTemplate rabbitTemplate;
    @Bean
    Queue queue() {
        return new Queue(queueName, false);
    }
    @Bean
    TopicExchange exchange() {
        return new TopicExchange("spring-boot-exchange");
    }
    @Bean
    Binding binding(Queue queue, TopicExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(queueName);
    }
    @Bean
    SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {
        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);
        container.setQueueNames(queueName);
        container.setMessageListener(listenerAdapter);
        return container;
    }
    @Bean
    Receiver receiver() {
        return new Receiver();
    }
    @Bean
    MessageListenerAdapter listenerAdapter(Receiver receiver) {
        return new MessageListenerAdapter(receiver, "receiveMessage");
    }
    public static void main(String[] args) throws InterruptedException {
        SpringApplication.run(Application.class, args);
    }
    @Override
    public void run(String... args) throws Exception {
        System.out.println("Waiting five seconds...");
        Thread.sleep(5000);
        System.out.println("Sending message...");
        rabbitTemplate.convertAndSend(queueName, "Hello from RabbitMQ!");
        receiver().getLatch().await(10000, TimeUnit.MILLISECONDS);
        context.close();
    }
}

. lang。无法评估org.springframework.boot.autoconfigure.jdbc上的条件。DataSourceTransactionManagerAutoConfiguration#transactionManager由于内部类未找到。如果你正在@ComponentScan springframework包(例如,如果你错误地将@ComponentScan放在默认包中)

似乎你的源文件是在src/main/java而不是在src/main/java/demo

你没有手动添加package hello;吗?我将该代码复制粘贴到从start.spring.io创建的新项目中,它可以在不触及任何东西的情况下工作。

相关内容

最新更新