Run spring boot using jdk9 using mosaic modules

What is wrong with this application. I thought the combination of class banners and modular cans is valid. For all cans that do not have an explicit information module, becomes an automatic module? When I remove my module-info.java, it works. Because IDEA uses the classpath for this case.

Java (TM) SE Runtime Environment (Build 9 + 176)

IntelliJ IDEA 2017.1.4

module-info.java

module test { requires spring.boot.autoconfigure; requires spring.boot; } 

App.java

 package com.foo.test; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class App { public static void main(String[] args) { SpringApplication.run(App.class, args); } } 

pom.xml

 <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"> <modelVersion>4.0.0</modelVersion> <groupId>com.foo.test</groupId> <artifactId>test</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.0.M2</version> </parent> <name>test</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.9</maven.compiler.source> <maven.compiler.target>1.9</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <repositories> <repository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/libs-milestone</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> </project> 

An exception in the "main" thread is java.lang.IllegalArgumentException: Can not an interface instance org.springframework.context.ApplicationContextInitializer: org.springframework.boot.context.ConfigurationWarningsApplicationContextInitializer in spring.boot @ 2.0.0.M2 / org.sprf. SpringApplication.createSpringFactoriesInstances (SpringApplication.java:439) in spring.boot @ 2.0.0.M2 / org.springframework.boot.SpringApplication.getSpringFactoriesInstances (SpringApplication.java:418) in spring.boot @ 2.0.0.M2 / org. springframework.boot.SpringApplication.getSpringFactoriesInstances (SpringApplication.java:409) at spring.boot @ 2.0.0.M2 / org.springframework.boot.SpringApplication. (SpringApplication.java:266) at spring.boot @ 2.0.0.M2 / org.springframework.boot.SpringApplication. (SpringApplication.java:247) at spring.boot @ 2.0.0.M2 / org.springframework.boot.SpringApplication.run (SpringApplication.java:1245) at spring.boot @ 2.0.0.M2 / org.springframework.boot .SpringApplication.run (SpringApplication.java:1233) at test / com.foo.test.App.main (App.java:10) Called: java.lang.NoClassDefFoundError: java / sql / SQLException in spring.beans @ 5.0. 0.RC2 / org.springframework.beans.BeanUtils.instantiateClass (BeanUtils.java:145) at spring.boot @ 2.0.0.M2 / org.springframework.boot.SpringApplication.createSpringFactoriesInstances (SpringApplication.java:435) ... 7 more Caused by: java.lang.ClassNotFoundException: java.sql.SQLException on java.base / jdk.internal.loader.BuiltinClassLoader.loadClass (BuiltinClassLoader.javahaps82) in java.base / jdk.internal.loader.ClassLoaders $ App .loadClass (ClassLoaders.java:185) in java.base / java.lang.ClassLoader.loadClass (ClassLoader.java:496) ... 9 more

+5
source share
3 answers

I assume spring.boot is an automatic module. An automatic module does not declare it as a dependency, so you should use --add-modules to make sure that all explicit modules are needed. If spring.boot was an explicit module, I assume it will require java.sql and you will not have this problem.

+5
source

Finally, I realized ... my info module should look like this:

 module test { requires java.sql; // my real problem solved with this requires spring.boot.autoconfigure; requires spring.boot; exports com.foo.test; // subsequent error 1: beeing accessible for some spring modules opens com.foo.test to spring.core; // subsequent error 2: beeing accessible for spring.core in a deep reflection way } 

Can someone explain why I need java.sql; inside my own module when i don't use it?

+3
source

This is almost certainly because you are missing the jdbc driver for MySql. you need to use this dependency: -

 <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>6.0.5</version> </dependency> 
0
source

Source: https://habr.com/ru/post/1269487/


All Articles