当运行我的springbootapp时,它在初始化后立即停止,没有错误. 我try 使用以下函数实现一个解决方案:
public static void waitForTermination() {
try {
// Wait indefinitely
Object lock = new Object();
synchronized (lock) {
lock.wait();
}
} catch (InterruptedException e) {
// Handle interruption if needed
Thread.currentThread().interrupt();
}
}
这阻止了它停止,然而,API本身没有响应任何请求, 此外,在判断过程本身时,它显示:
Tcp 127.0.0.1:53768 127.0.0.1:53767已建立11584
以下是主要的应用程序:
public class Main {
public static void main(String[] args) {
NovaOpt novaOpt = NovaOpt.GetInstance();
SpringApplication springApplication = new SpringApplication(Main.class);
springApplication.setDefaultProperties(Collections.singletonMap("server.port", "8090"));
springApplication.run(args);
// waitForTermination();
}
public static void waitForTermination() {
try {
// Wait indefinitely
Object lock = new Object();
synchronized (lock) {
lock.wait();
}
} catch (InterruptedException e) {
// Handle interruption if needed
Thread.currentThread().interrupt();
}
}
}
下面是我创建的用于管理路由的Spring类:
package org.example;
import novj.publ.api.NovaOpt;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api")
public class Spring {
NovaOpt novaOpt = NovaOpt.GetInstance();
@GetMapping("/hello")
public String sayHello() {
return "Hello, World!";
}
@GetMapping("/GetScreenBrightness/{screenIp}")
public String getScreenBrightness(@RequestParam("screenIp") String screenIp) {
String username = System.getenv("USERNAME");
String password = System.getenv("PASSWORD");
// NovaHelper.fullLogin(novaOpt , username , password , screenIp);
System.out.printf("Username:" + username);
return "Hello";
}
}
这是我的build.gradle:
plugins {
id 'java'
id "org.springframework.boot" version "3.1.0"
}
group = 'org.example'
version = '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation platform('org.junit:junit-bom:5.9.1')
testImplementation 'org.junit.jupiter:junit-jupiter'
implementation files('src/NOVASDK/SDK/NovaSdk.jar')
implementation files('src/Libs/gson-2.2.2.jar/gson-2.2.2.jar');
implementation('org.springframework:spring-web:6.0.9')
implementation platform('org.springframework.boot:spring-boot-dependencies:2.7.8')
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
// implementation 'org.springframework.boot:spring-boot-starter-web:latest.release'
}
test {
useJUnitPlatform()
}