Ich lerne Spring Boot. Ich habe gerade mein erstes Projekt mit Maven, Spring Boot, Spring Rest Support und MongoDB erstellt. Es kompiliert erfolgreich, aber es löst alle Abhängigkeiten auf, aber kompiliert die Java-Klassen überhaupt nicht.Spring Boot - Spring Rest - Build Paket
Nach der Kompilierung wird die JAR-Datei ordnungsgemäß erstellt. Sie enthält den Ordner lib, Metadaten usw., enthält jedoch keine Projektklassendatei.
Daher, wenn ich das Projekt mit mvn Spring-Boot: run ausführen, löst es eine Ausnahme, die Klasse nicht gefunden (Main-Methode-Klasse für Spring-Boot-Initialisierung).
Bitte legen nahe, was ich hier falsch mache, hier ist meine Maven-Konfigurationsklasse:
<?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>
<properties>
<java.version>1.6</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>com.assignment.BootInitializer</start-class>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.9.RELEASE</version>
</parent>
<groupId>com.assignment</groupId>
<artifactId>spring-assignment</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Und hier ist die Haupt initializer Klasse:
package com.assignment;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class BootInitializer {
public static void main(String[] args) {
SpringApplication.run(BootInitializer.class, args);
}
}
Was muss ich tun, um Stellen Sie sicher, dass Maven die Java-Klassen kompiliert und sie in die JAR-Datei aufnimmt.
Danke.
Beginnen Sie mit einem grundlegenden Projekt wie https://projects.spring.io/spring-boot/ und versuchen Sie es auszuführen, wenn alles gut geht, fügen Sie neue Funktionalität Schritt für Schritt mit frecuent Compilations – jmhostalet
Frage ist, warum Java-Code nicht ist kompiliert werden ... –
Hier ist das Beispiel, wie Sie es tun http://javabycode.com/spring-framework-tutorial/spring-boot-tutorial/spring-boot-restful-web-services-example.html –