Мой руководитель попросил меня преобразовать старый проект Maven, который у нас есть, в проект Spring Boot, чтобы мы могли получить доступ к бэкэнду проекта через взаимодействие RESTful (до этого бэкэнд проекта был доступен только через консольный интерфейс).
Итак, сначала я добавил простое приложение Spring Boot в отдельный пакет project. После этого я начал расширять pom.xml проекта зависимостями, необходимыми для Spring Boot, и скорректировал общую настройку проекта. Теперь я попытался запустить бэкэнд старого проекта, который, как оказалось, работал. Однако простое приложение Spring Boot этого не сделало.
Я сузил проблему до конфликтующей зависимости в "старой" части pom.xml:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.6.1</version>
</dependency>
Когда я оставляю эту зависимость в pom.xml, старый бэкэнд работает, но приложение Spring Boot не работает со следующей ошибкой:
WARN: Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
Если я прокомментирую эту зависимость, приложение Spring работает полностью нормально, но старый бэкэнд не работает. Я использую версию 2.0.4.RELEASE
от spring-boot-admin-starter-server
. Я думаю, что старая бэкэнд-версия пакета регистрации отличается от той, что включена в spring-boot-admin-starter-server
. Однако мне как-то нужны обе версии в моем проекте.
Что невозможно:
То, что я уже пробовал, но безуспешно:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Есть ли у кого-нибудь предложения, как решить эту проблему? Я был бы очень признателен. Я не привык решать подобные проблемы с зависимостями. Пожалуйста, извините, если я упускаю что-то очевидное.
-лема
EDIT pom.xml (unfortunately I had to leave out bigger parts of it) :
<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>
...
<packaging>jar</packaging>
<description></description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-boot-admin.version>2.0.2</spring-boot-admin.version>
<spring-boot-dependencies.version>2.0.4.RELEASE</spring-boot-dependencies.version>
...
<rat.skip>true</rat.skip>
<log4j-version>2.6.1</log4j-version>
</properties>
<repositories>
...
</repositories>
<dependencyManagement>
<dependencies>
<!-- Necessary dependency for running Spring Boot without starter parent -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-releasetrain</artifactId>
<version>Fowler-SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
...
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>${spring-boot-admin.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
...
<!-- TODO The version of this dependency lets Spring Boot fail, but is
necessary tu run the old backend -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-iostreams</artifactId>
<version>${log4j-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
<version>${log4j-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>${log4j-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jul</artifactId>
<version>${log4j-version}</version>
</dependency>
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
<version>1.13</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
...
</dependencies>
<build>
<defaultGoal>verify</defaultGoal>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
...
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>prepare-config-zip</id>
<phase>prepare-package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>${basedir}/src/main/assembly/config.xml</descriptor>
</descriptors>
<finalName>configs</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
<execution>
<id>prepare-dist-zip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptor>src/main/assembly/dist.xml</descriptor>
<finalName>...</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<configuration>
<rules>
<requireJavaVersion>
<version>1.8</version>
</requireJavaVersion>
</rules>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>attach-standalone</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>standalone</shadedClassifierName>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>dont-attach-standalone</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<!-- Prevent huge shaded artifacts from being deployed to Artifactory -->
<outputFile>...</outputFile>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
EDIT: I just found out that if you remove the version element inside of the conflicting dependency the Spring Boot Application works, but unfortunately the backend then fails.
Ой, извини. Я забыл упомянуть, что я не наследую от Spring Boot Starter в <parent>
, потому что родительский элемент занят другим модулем, от которого наследуется старый бэкэнд. Если я запускаю приложение Spring без spring-boot-admin-starter-server
, я получаю: Exception in thread "main" java.lang.Error: Unresolved compilation problem: SpringApplication cannot be resolved at ...restAdapter.RestfulServerLauncher.main(RestfulServerLauncher.java:10)
Вы должны сделать так, чтобы приложение Spring Boot работало без внутренних зависимостей. Затем по очереди добавляйте зависимости, запускайте и проверяйте, не ломается ли что-нибудь. Можете поделиться pom файлом?
Прежде всего. Спасибо за вашу помощь. ;) Как было сказано выше, приложение весенней загрузки работает отлично, пока я закомментирую конфликтующую зависимость. Как вы и предположили, я добавлял бэкэнд-зависимости по одной за раз. Это привело меня к выводу, что источником проблемы должна быть зависимость журналирования. Я предоставлю pom.xml.
Итак, я нашел решение, но, вероятно, это не лучший способ сделать это:
Я просто заменил <spring-boot-dependencies.version>2.0.4</spring-boot-dependencies.version>
на более старую версию, совместимую с конфликтующей зависимостью ведения журнала, а именно версию 1.4.7.RELEASE
.
Это последняя версия, в которой приложение Spring Boot и серверная часть работают одновременно (это выяснилось методом проб и ошибок).
В любом случае, большое спасибо за вашу помощь.
Ваше здоровье
Можете ли вы исключить
spring-boot-admin-starter-server
из файла pom, чтобы просто убедиться в правильности вашего предположения о конфликтующем пакете регистрации? Мы просто хотим устранить некоторые зависимости, чтобы изолировать проблему и выяснить причину. На самом деле вам не нуженspring-boot-admin-starter-server
, чтобы сделать проект весенней загрузкой.