Skip to content
Advertisement

Spring Boot Application won’t start (IllegalStateException could not evaluate condition on DevToolsDataSourceAutoConfiguration)

I’ve tried to start my Spring Boot Application using IntelliJ. However, I cannot seem to make it work no matter whatever solutions I tried to implement to fix it. I believe it has something to do with spring.autoconfigure package, yet the root problem remains a mystery to me.

I am trying to take advantage of both Maven Multi Module System as well as Java Platform Module System. Below is my pom.xml, module-info.java files and project structure.

Project Structure

Simplified Project Structure

Note that there is a parent pom.xml file and each sub-module has its own pom.xml file. Each sub-module has its own module-info.java file as well.

Parent pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <packaging>pom</packaging>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>parent</artifactId>
    <version>0.0.1</version>
    <name>Demo Project</name>
    <description>Demo Project Description</description>

    <properties>
        <java.version>11</java.version>
    </properties>

    <!--Add each module here -->
    <modules>
        <module>webapp</module>
        <module>persistence</module>
        <module>facade</module>
        <module>service</module>
        <module>security</module>
        <module>domain</module>
    </modules>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <version>2.5.1</version>
                    <configuration>
                        <mainClass>com.example.MainApplication</mainClass>
                        <excludes>
                            <exclude>
                                <groupId>org.projectlombok</groupId>
                                <artifactId>lombok</artifactId>
                            </exclude>
                        </excludes>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.1</version>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                    </configuration>
                </plugin>
                <plugin>
                    <!-- For testing -->
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.0.0-M5</version>
                    <configuration>
                        <testFailureIgnore>true</testFailureIgnore>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

</project>

webapp pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>parent</artifactId>
        <groupId>com.example</groupId>
        <version>0.0.1</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <packaging>jar</packaging>
    <!--    <version>0.0.1</version>-->

    <artifactId>webapp</artifactId>

    <dependencies>
        <!-- Add dependencies for `webapp` module here -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.example</groupId>
            <artifactId>facade</artifactId>
            <version>0.0.1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.example</groupId>
            <artifactId>domain</artifactId>
            <version>0.0.1</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>

</project>

webapp module-info.java

module webapp {
    requires domain;
    requires facade;

    requires spring.web;
    requires spring.boot;
    requires spring.boot.autoconfigure;
    requires spring.context;
}

Below is what I tried: So when I run the application as it is I get the following exception

Exception in thread "restartedMain" java.lang.IllegalAccessException: class org.springframework.boot.devtools.restart.RestartLauncher (in module spring.boot.devtools) cannot access class com.example.MainApplication (in module webapp) because module webapp does not export com.example to module spring.boot.devtools
    at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:361)
    at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:591)
    at java.base/java.lang.reflect.Method.invoke(Method.java:558)
    at spring.boot.devtools@2.5.1/org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)

What I did to tackle this problem was changing webapp/module-info.java from

module webapp {
}

to

open module webapp {
}

Aftwerwards, though, I got the following exception

java.lang.IllegalStateException: Could not evaluate condition on org.springframework.boot.devtools.autoconfigure.DevToolsDataSourceAutoConfiguration due to javax/sql/DataSource not found. Make sure your own configuration does not rely on that class. This can also happen if you are @ComponentScanning a springframework package (e.g. if you put a @ComponentScan in the default package by mistake)
    at spring.boot.autoconfigure@2.5.1/org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:54) ~[spring-boot-autoconfigure-2.5.1.jar:na]
    at spring.context@5.3.8/org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108) ~[spring-context-5.3.8.jar:na]
    at spring.context@5.3.8/org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader$TrackedConditionEvaluator.shouldSkip(ConfigurationClassBeanDefinitionReader.java:489) ~[spring-context-5.3.8.jar:na]
    at spring.context@5.3.8/org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:140) ~[spring-context-5.3.8.jar:na]
    at spring.context@5.3.8/org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:129) ~[spring-context-5.3.8.jar:na]
    at spring.context@5.3.8/org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:343) ~[spring-context-5.3.8.jar:na]
    at spring.context@5.3.8/org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:247) ~[spring-context-5.3.8.jar:na]
    at spring.context@5.3.8/org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:311) ~[spring-context-5.3.8.jar:na]
    at spring.context@5.3.8/org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:112) ~[spring-context-5.3.8.jar:na]
    at spring.context@5.3.8/org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:746) ~[spring-context-5.3.8.jar:na]
    at spring.context@5.3.8/org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:564) ~[spring-context-5.3.8.jar:na]
    at spring.boot@2.5.1/org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-2.5.1.jar:na]
    at spring.boot@2.5.1/org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[spring-boot-2.5.1.jar:na]
    at spring.boot@2.5.1/org.springframework.boot.SpringApplication.run(SpringApplication.java:338) ~[spring-boot-2.5.1.jar:na]
    at spring.boot@2.5.1/org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) ~[spring-boot-2.5.1.jar:na]
    at spring.boot@2.5.1/org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) ~[spring-boot-2.5.1.jar:na]
    at webapp/com.example.MainApplication.main(MainApplication.java:10) ~[classes/:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
    at spring.boot.devtools@2.5.1/org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.5.1.jar:na]
Caused by: java.lang.NoClassDefFoundError: javax/sql/DataSource
    at spring.boot.devtools@2.5.1/org.springframework.boot.devtools.autoconfigure.DevToolsDataSourceAutoConfiguration$DevToolsDataSourceCondition.getMatchOutcome(DevToolsDataSourceAutoConfiguration.java:183) ~[spring-boot-devtools-2.5.1.jar:na]
    at spring.boot.autoconfigure@2.5.1/org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47) ~[spring-boot-autoconfigure-2.5.1.jar:na]
    ... 21 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.sql.DataSource
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) ~[na:na]
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[na:na]
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ~[na:na]
    ... 23 common frames omitted
  • I tried setting spring.devtools.restart.enabled=false. Same error followed.

  • I tried removing spring-boot-devtools from the list of dependencies. No error log yet start process exits with error code 0

  • I tried adding h2 database dependency just to see what happens. No good.

  • I tried changing spring-boot-devtools <scope> value and even commenting it out. No good.

  • I tried excluding DevToolsDataSourceAutoConfiguration.class from AutoConfiguration. No good.

  • I tried adding exports com.example; to module-info.java. No good.

  • If I run mvn test, mvn clean install, mvn spring-boot:run, I don’t get a single error and server is running just fine.

  • MainApplication.java resides at webapp/src/main/java/com/example/MainApplication.java.

package com.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


@SpringBootApplication
public class MainApplication {
    public static void main(String[] args) {
        SpringApplication.run(MainApplication.class, args);
    }
}

Why is spring.autoconfigure trying to find a DataSource? Is IntelliJ‘s classpath messed up, and I need to update its dependencies manually? If I configure a proper database (such as mssql), would I still be facing this issue going forward?

What confuses me the most is that I get no error triggering the server to run by typing mvn spring-boot:run command. To be honest, this is what makes me think the problem has to do with IntelliJ's classpath settings rather than project structure and configuration.

Any help would be greatly appreciated. Thanks.

Advertisement

Answer

Editing module-info.java as the following resolved the problem for me

open module webapp {
    requires spring.web;
    requires spring.boot;
    requires spring.boot.autoconfigure;
    requires spring.context;
    
    requires org.apache.tomcat.embed.core;
}
Advertisement