JDK9 + - тип org.springframework.beans.factory.annotation.Autowire не может быть разрешен.На него косвенно ссылаются необходимые файлы .class - PullRequest
0 голосов
/ 14 мая 2019

Я пытаюсь запустить очень простой мир hello для изучения WebFlux (https://dzone.com/articles/spring-webflux-getting-started).

. Я могу успешно скомпилировать проект, но я получаю сообщение об ошибке, упомянутое в теме в Eclipse, а также когдаmvn spring-boot: run

С экрана «Проблемы Eclipse»:

Description Resource    Path    Location    Type
The project was not built since its build path is incomplete. Cannot find the class file for org.springframework.beans.factory.annotation.Autowire. Fix the build path then try building this project   myspringwebfluxplanet       Unknown Java Problem

The type org.springframework.beans.factory.annotation.Autowire cannot be resolved. It is indirectly referenced from required .class files   ExampleRouter.java  /myspringwebfluxplanet/src/main/java/com/mydeveloperplanet/myspringwebfluxplanet/examples   line 1  Java Problem

Если уместно, у меня установлен JDK11, а проект зависит от JDK9.

Я гуглювокруг и многие решения для аналогичной проблемы связаны с путем сборки. Хорошо, я предполагаю, что если бы это было так, я не смог бы собрать и скомпилировать его. Я имею в виду, что я не получил никакого исключения при очистке дерева (mvn clean зависимость:дерево), а затем

# mvn clean compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------< com.mydeveloperplanet:myspringwebfluxplanet >-------------
[INFO] Building myspringwebfluxplanet 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ myspringwebfluxplanet ---
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ myspringwebfluxplanet ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\_d\samples\myspringwebfluxplanet\src\main\resources
[INFO] skip non existing resourceDirectory C:\_d\samples\myspringwebfluxplanet\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ myspringwebfluxplanet ---
[INFO] Required filename-based automodules detected. Please don't publish this project to a public artifact repository!
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 7 source files to C:\_d\samples\myspringwebfluxplanet\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.243 s
[INFO] Finished at: 2019-05-14T13:20:39-03:00
[INFO] ------------------------------------------------------------------------

Я почти уверен, что мне не хватает какой-то базовой концепции Modularity, WebFlux + Reactor.

Pom

<?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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.mydeveloperplanet</groupId>
    <artifactId>myspringwebfluxplanet</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.version>3.3.9</maven.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <jdk.version>1.9</jdk.version>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.7.0</version>
                    <configuration>
                        <source>${jdk.version}</source>
                        <target>${jdk.version}</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

</project>

module-info.java

module com.mydeveloperplanet.myspringwebfluxplanet {
    requires reactor.core;
    requires spring.web;
    requires spring.context;
    requires spring.webflux;
    requires spring.boot;
    requires spring.boot.autoconfigure;
}

*** Отредактировано

Если я попытаюсь скомпилировать с помощью командной строки, я смогу успешно работать, пока получаю сообщение об ошибке в Eclipse. Я обнаружил Java 9: ​​java.lang.ClassNotFoundException: java.sql.SQLException в приложении Spring Boot , предлагающем добавить «--add-modules java.sql», но это ничего не меняет в моем случае.Я обнаружил, что кто-то решает аналогичную проблему с InteliJ Получение noclassfoundexception: java.sql.SQLException в идее intellij для jdk 11 (Пожалуйста, не сравнивайте и не указывайте, что я использую InteliJ, поскольку в моем квесте нет ничего общего)

Из командной строки (успех):

# mvn clean compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------< com.mydeveloperplanet:myspringwebfluxplanet >-------------
[INFO] Building myspringwebfluxplanet 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ myspringwebfluxplanet ---
[INFO] Deleting C:\_d\samples\myspringwebfluxplanet\target
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ myspringwebfluxplanet ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\_d\samples\myspringwebfluxplanet\src\main\resources
[INFO] skip non existing resourceDirectory C:\_d\samples\myspringwebfluxplanet\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ myspringwebfluxplanet ---
[INFO] Required filename-based automodules detected. Please don't publish this project to a public artifact repository!
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 7 source files to C:\_d\samples\myspringwebfluxplanet\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  7.470 s
[INFO] Finished at: 2019-05-15T11:04:28-03:00
[INFO] ------------------------------------------------------------------------

myuser@mycomputer C:\_d\samples\myspringwebfluxplanet
# mvn spring-boot:run
[INFO] Scanning for projects...
[INFO]
[INFO] ------------< com.mydeveloperplanet:myspringwebfluxplanet >-------------
[INFO] Building myspringwebfluxplanet 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:2.0.0.RELEASE:run (default-cli) > test-compile @ myspringwebfluxplanet >>>
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ myspringwebfluxplanet ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\_d\samples\myspringwebfluxplanet\src\main\resources
[INFO] skip non existing resourceDirectory C:\_d\samples\myspringwebfluxplanet\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ myspringwebfluxplanet ---
[INFO] Required filename-based automodules detected. Please don't publish this project to a public artifact repository!
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:testResources (default-testResources) @ myspringwebfluxplanet ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\_d\samples\myspringwebfluxplanet\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ myspringwebfluxplanet ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to C:\_d\samples\myspringwebfluxplanet\target\test-classes
[INFO]
[INFO] <<< spring-boot-maven-plugin:2.0.0.RELEASE:run (default-cli) < test-compile @ myspringwebfluxplanet <<<
[INFO]
[INFO]
[INFO] --- spring-boot-maven-plugin:2.0.0.RELEASE:run (default-cli) @ myspringwebfluxplanet ---

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.0.RELEASE)

2019-05-15 11:04:45.211  INFO 8524 --- [           main] c.m.myspringwebfluxplanet.Application    : Starting Application on DESKTOP-AKCNE7F with PID 8524 (C:\_d\samples\myspringwebfluxplanet\target\classes started by resource in C:\_d\samples\myspringwebfluxplanet)
2019-05-15 11:04:45.223  INFO 8524 --- [           main] c.m.myspringwebfluxplanet.Application    : No active profile set, falling back to default profiles: default
2019-05-15 11:04:45.324  INFO 8524 --- [           main] onfigReactiveWebServerApplicationContext : Refreshing org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext@5a68e0f8: startup date [Wed May 15 11:04:45 BRT 2019]; root of context hierarchy
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils$1 (file:/C:/Users/resource/.m2/repository/org/springframework/spring-core/5.0.4.RELEASE/spring-core-5.0.4.RELEASE.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2019-05-15 11:04:47.927  INFO 8524 --- [           main] o.s.w.r.f.s.s.RouterFunctionMapping      : Mapped ((GET && /example) && Accept: [text/plain]) -> com.mydeveloperplanet.myspringwebfluxplanet.examples.ExampleRouter$$Lambda$442/0x0000000100691840@768f81f
2019-05-15 11:04:48.420  INFO 8524 --- [           main] o.s.w.r.f.s.s.RouterFunctionMapping      : Mapped ((GET && /exampleFurther1) && Accept: [text/plain]) -> com.mydeveloperplanet.myspringwebfluxplanet.examples.ExampleRouter$$Lambda$444/0x00000001006ba040@26ddf6b5
((GET && /exampleFurther2) && Accept: [text/plain]) -> com.mydeveloperplanet.myspringwebfluxplanet.examples.ExampleRouter$$Lambda$445/0x00000001006ba440@46a9ce9c
((GET && /exampleFurther3) && Accept: [text/plain]) -> com.mydeveloperplanet.myspringwebfluxplanet.examples.ExampleRouter$$Lambda$446/0x00000001006ba840@bb74974
2019-05-15 11:04:48.437  INFO 8524 --- [           main] o.s.w.r.f.s.s.RouterFunctionMapping      : Mapped ((GET && /hello) && Accept: [text/plain]) -> com.mydeveloperplanet.myspringwebfluxplanet.greeting.GreetingRouter$$Lambda$447/0x00000001006bac40@4b5ff01d
2019-05-15 11:04:48.473  INFO 8524 --- [           main] o.s.w.r.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.reactive.resource.ResourceWebHandler]
2019-05-15 11:04:48.476  INFO 8524 --- [           main] o.s.w.r.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.reactive.resource.ResourceWebHandler]
2019-05-15 11:04:48.694  INFO 8524 --- [           main] o.s.w.r.r.m.a.ControllerMethodResolver   : Looking for @ControllerAdvice: org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext@5a68e0f8: startup date [Wed May 15 11:04:45 BRT 2019]; root of context hierarchy
2019-05-15 11:04:51.618  INFO 8524 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2019-05-15 11:04:52.688  INFO 8524 --- [ctor-http-nio-1] r.ipc.netty.tcp.BlockingNettyContext     : Started HttpServer on /0:0:0:0:0:0:0:0:8080
2019-05-15 11:04:52.689  INFO 8524 --- [           main] o.s.b.web.embedded.netty.NettyWebServer  : Netty started on port(s): 8080
2019-05-15 11:04:52.696  INFO 8524 --- [           main] c.m.myspringwebfluxplanet.Application    : Started Application in 8.217 seconds (JVM running for 18.277)
>> result = Hello, Spring!
2019-05-15 11:05:12.016  WARN 8524 --- [ctor-http-nio-4] .a.w.r.e.DefaultErrorWebExceptionHandler : Failed to handle request [GET http://localhost:8080/favicon.ico]: Response status 404

Из Eclipse

enter image description here

и если я игнорируюошибка, которая находится в теме моего вопроса, я получаю

Исключение в потоке "основной" java.lang.IllegalArgumentException: не удается создать экземпляр интерфейса org.springframework.context.ApplicationContextInitializer: org.springframework.boot.context.InpplicationWisionпо адресу spring.boot@2.0.0.RELEASE/org.springframework.boot.SpringApplication.createSpringFactoriesInstances (SpringApplication.java:441) по адресу spring.boot@2.0.0.RELEASE/org.springframework.boot.SpringApplication.ppInprings.Java: 420) на spring.boot@2.0.0.RELEASE/org.springframework.boot.SpringApplication.getSpringFactoriesInstances (SpringApplication.java:411) в spring.boot@2.0.0.RELEASE/org.springframework.boot.SpringApplication. (SpringApplication.java:266) в spring.boot@2.0.0.RELEASE/org.springframe.boot.SpringApplication. (SpringApplication.java:247) по адресу spring.boot@2.0.0.RELEASE/org.springframework.boot.SpringApplication.run (SpringApplication.java:1246) по адресу spring.boot@2.0.0.RELEASE/org.springframework.boot.SpringApplication.run (SpringApplication.java:1234) по адресу com.mydeveloperplanet.myspringwebfluxplanet / com.mydeveloperplanet.myspringwebfluxplanet.Application.main (Application.java:11).sql / SQLException в org.springframework.beans.BeanUtils.instantiateClass (BeanUtils.java:168) в spring.boot@2.0.0.RELEASE/org.springframework.boot.SpringApplication.createSpringFactoriesInstances (SpringApplication) ...Еще 7 причин: java.lang.ClassNotFoundException: java.sql.SQLException at java.base / jdk.internal.loader.BuiltinClassLoader.loadClass (BuiltinClassLoader.java:583) в java.base / jdk.internal.loader.ClassLoaders $ AppClassLoader.loadClass (ClassLoaders.java:178) в java.base / java.lang.ClassLoader.loadClassj: Classo:521) ... еще 9

*** отредактировано

Я отредактировал свой pom.xml, добавив --add-modules

<pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <source>${jdk.version}</source>
                <target>${jdk.version}</target>
                <compilerargs>
                    <arg>--add-modules</arg>
                    <arg>java.sql</arg>
                </compilerargs>
            </configuration>
        </plugin>
    </plugins>
</pluginManagement>
...