![](/img/trans.png)
[英]load js from filesystem into spring boot jar application (with thymeleaf)
[英]Change default Port of Spring Boot application from frontend with thymeleaf
是否可以通過@Controller 上的端點從前端(通過使用百里香葉)更改 spring 引導端口?
以及如何使用新配置的端口以編程方式重新啟動應用程序?
如此處所述,您可以像這樣設置服務器端口:
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.stereotype.Component;
@Component
public class AppCustomContainer
implements WebServerFactoryCustomizer<ConfigurableWebServerFactory> {
@Override
public void customize(ConfigurableWebServerFactory factory) {
factory.setPort(1234);
}
}
您可以使用文件而不是 1234 來存儲端口(更改端口時)並在啟動時加載它
之后,您可以按照此處所述重新啟動應用程序:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
application.properties
中啟用重啟: management.endpoint.restart.enabled = true
RestartEndpoint
的實例:@Autowired
private RestartEndpoint restartEndpoint;
並運行它以重新啟動:
Thread restartThread = new Thread(restartEndpoint::restart);
restartThread.setDaemon(false);
restartThread.start();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.