首先要说的是,我是一个相对缺乏经验的程序员。
我的任务是将给定的 gradle 项目导入到 Spring Boot Tool Suite (sts) 中。我已经下载了springboot cli、java、gradle。 & 过去,我能够在另一个项目上完美运行 spring,不幸的是我不得不更换硬盘,所以我丢失了相当多的下载量。
尽管如此,我的问题分为两部分。首先,我的工具套件(ide?基本上是 eclipse)无法将我的项目识别为 java 项目,我尝试了很多选项,唯一的解决方法是在 .project 文件中的 buildCommand 标记内对 org.eclipse.core.javabuilder 进行硬编码,我不记得在我的上一个项目中这样做了。
这里是后端文件夹的目录树(与前端无关)
.
├── build.gradle
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── src
├── main
│ ├── java
│ │ └── ca
│ │ └── mcgill
│ │ └── ecse321
│ │ └── eventregistration
│ │ ├── EventRegistrationApplication.java
│ │ ├── controller
│ │ │ ├── ApiError.java
│ │ │ ├── EventRegistrationRestController.java
│ │ │ └── RestExceptionHandler.java
│ │ ├── dao
│ │ │ ├── EventRegistrationRepository.java
│ │ │ ├── EventRepository.java
│ │ │ ├── PersonRepository.java
│ │ │ └── RegistrationRepository.java
│ │ ├── dto
│ │ │ ├── EventDto.java
│ │ │ ├── PersonDto.java
│ │ │ └── RegistrationDto.java
│ │ ├── model
│ │ │ ├── Event.java
│ │ │ ├── Person.java
│ │ │ ├── Registration.java
│ │ │ └── RegistrationManager.java
│ │ └── service
│ │ └── EventRegistrationService.java
│ └── resources
│ └── application.properties
└── test
└── java
└── ca
└── mcgill
└── ecse321
└── eventregistration
└── service
├── event
│ └── TestCinema.java
├── payment
│ ├── TestPaymentWithCreditCard.java
│ ├── TestPaymentWithCreditCardData.java
│ └── TestUtils.java
└── role
├── PromoterRoleTestData.java
└── TestPromoterRole.java
此外,这是我的 build.gradle 文件
buildscript {
ext {
springBootVersion = '2.1.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
runtimeOnly 'org.postgresql:postgresql'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
这解决了我的 java 问题,但我仍然无法让它作为 spring boot 应用程序运行。
请帮忙,因为我不知道从哪里继续!我需要能够将该项目作为后端服务的 Spring Boot 应用程序运行,因为然后我将负责使用 vue.js 将其连接到前端服务。 (别担心我得到了那部分)!
这也是我的 EventRegistration.java 文件
package ca.mcgill.ecse321.eventregistration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.SpringApplication;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
@RestController
@SpringBootApplication
public class EventRegistrationApplication {
public static void main(String[] args) {
SpringApplication.run(EventRegistrationApplication.class, args);
}
@RequestMapping("/")
public String greeting() {
return "ECSE321 Event Registration Application - Backend base URL.\n"
+ "Use the API methods to interact with the backend!";
}
}
最佳答案
虽然我停止使用 eclipse 但以下用于解决这样的情况
1.
- Eclipse ->首选项-->java-->安装的JRE-->选择标准虚拟机
(可以在这里找到jdk1.8.0_51.jdk/Contents/Home)
2.
- 将 JRE 系统库添加到您的项目构建路径
- 右键单击项目>选择构建路径>库>
- 如果列出了 JRE,则很好,否则> 添加库
- 选择JRE库并完成
关于java - 无法解析 java 构建/Spring,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59113421/