我正在尝试创建Spring Boot应用程序以与Apache ActiveMQ进行协作。
在启动期间,我收到以下"非致命"错误:
java.lang.ClassNotFoundException: org.springframework.data.web.config.EnableSpringDataWebSupport
at java.net.URLClassLoader$1.run(Unknown Source) ~[na:1.8.0_25]
at java.net.URLClassLoader$1.run(Unknown Source) ~[na:1.8.0_25]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_25]
at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_25]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_25]
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) ~[na:1.8.0_25]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_25]
java.lang.ClassNotFoundException: org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
at java.net.URLClassLoader$1.run(Unknown Source) ~[na:1.8.0_25]
at java.net.URLClassLoader$1.run(Unknown Source) ~[na:1.8.0_25]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_25]
at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_25]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_25]
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) ~[na:1.8.0_25]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_25]
这是我的档案:
@Configuration
@EnableJms
public class ActiveMQTestConfig {
@Bean
// Strictly speaking this bean is not necessary as boot creates a default
JmsListenerContainerFactory<?> myJmsContainerFactory(ConnectionFactory connectionFactory) {
SimpleJmsListenerContainerFactory factory = new SimpleJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
return factory;
}
}
@Configuration
@ComponentScan("com.example.messages")
@SpringBootApplication
public class TestConfig {
}
@Component
public class Receiver {
/**
* Get a copy of the application context
*/
@Autowired
ConfigurableApplicationContext context;
/**
* When you receive a message, print it out, then shut down the application.
* Finally, clean up any ActiveMQ server stuff.
*/
@JmsListener(destination = "mailbox-destination", containerFactory = "myJmsContainerFactory")
public void receiveMessage(String message) {
System.out.println("Received <" + message + ">");
context.close();
FileSystemUtils.deleteRecursively(new File("activemq-data"));
}
}
@SpringApplicationConfiguration(classes = { TestConfig.class, ActiveMQTestConfig.class })
@RunWith(SpringJUnit4ClassRunner.class)
public class ReceiverTest {
@Autowired
private JmsTemplate jmsTemplate;
@Test
public void testReceiver() {
// Clean out any ActiveMQ data from a previous run
FileSystemUtils.deleteRecursively(new File("activemq-data"));
// Send a message
MessageCreator messageCreator = new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
return session.createTextMessage("ping!");
}
};
System.out.println("Sending a new message.");
jmsTemplate.send("mailbox-destination", messageCreator);
}
}
记录配置 - logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
</Pattern>
</layout>
</appender>
<logger name="org.springframework" level="debug" additivity="false">
<appender-ref ref="STDOUT" />
</logger>
<root level="error">
<appender-ref ref="STDOUT" />
</root>
</configuration>
来自parent-pom的依赖关系配置:
<!-- jUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- Aspectj -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Spring boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring.boot.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>${cdi-api.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>${commons-validator.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
此项目的依赖关系配置:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-broker</artifactId>
<version>${activemq.version}</version>
</dependency>
如何防止Spring Boot查找未使用的类和注释?我不需要这个项目中任何与网络相关的东西。
答案 0 :(得分:12)
Spring Boot自动配置通过特征检测工作,就像普通的Spring在某些地方一样(比如在Hibernate版本之间动态切换)。
通过检查框架,库或JDK的一些众所周知的类/方法/注释是否可用来进行特征检测。如果没有该功能不可用。
Spring Boot也不例外,它只是检查一个类是否可用。在您的情况下,它适用于Spring Data REST和Spring Security。对于调试Spring Boot,请在DEBUG中记录那些未检测到的功能。这是为了排除故障,如果某些东西不起作用,您可以看到您缺少的库的哪个部分。
要禁用日志记录,只需在DEBUG中记录所有内容。
答案 1 :(得分:4)
包括以下依赖
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>1.10.0.RELEASE</version>
</dependency>
答案 2 :(得分:0)
有解释:https://github.com/spring-projects/spring-boot/issues/4121 “Spring Framework使用ASM查看字节码。在这种情况下,它发现了一个不在类路径上的注释。这意味着有关注释的元数据将不可用,仅此而已。当实际加载类时,JVM会丢弃注释,因为它不在类路径上。“