Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring boot non-fatal errors ClassNotFoundException

I'm trying to create Spring Boot application for collaboration with Apache ActiveMQ.

During startup I receiving following "non-fatal" errors:

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]

This is my files:

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

    }

}

Logging configuration - 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>

Dependencies configuration from 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>

Dependencies configuration from this project:

<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>

How to prevent Spring Boot from looking for unused classes and annotations ? I don't need any web related stuff in this project.

like image 543
alexanoid Avatar asked Mar 07 '15 11:03

alexanoid


2 Answers

The Spring Boot auto configuration works by means of feature detection, much like plain Spring does at certain places (like dynamically switching between Hibernate versions).

Feature detection works by checking if some well known classes/methods/annotations of a framework, library or JDK are available. If not that feature is not available.

Spring Boot is no different, it simply checks if a class is available. In your case it is for Spring Data REST and Spring Security. For debugging Spring Boot logs those not detected features at DEBUG. This is for troubleshooting if something doesn't work you can see which part of a library you are missing.

To disable the logging simply don't log everything at DEBUG.

like image 184
M. Deinum Avatar answered Oct 06 '22 06:10

M. Deinum


Include the following depedency

       <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-commons</artifactId>
            <version>1.10.0.RELEASE</version>
        </dependency>
like image 24
vishnumanohar Avatar answered Oct 06 '22 06:10

vishnumanohar