gpt4 book ai didi

jhipster - 在哪里以及如何定义应用程序属性? - JHIpster

转载 作者:行者123 更新时间:2023-12-04 23:19:33 26 4
gpt4 key购买 nike

在 Spring Boot 中,可以在 application.properties 文件中定义应用程序属性。例如,Rest 的前缀可以定义为

spring.data.rest.basePath=api

对于基于 Spring Boot 的 JHipster,我猜可以在 application.yml 文件中定义一个应用程序属性。但是以下方法都不适合我:404 错误。
spring.data.rest.basePath: api

spring:
data:
rest:
basePath: api

另一种可能性是配置本身不起作用。

最佳答案

我有同样的问题,终于想通了!
引用自 Jhipster 网站:

Your generated application can also have its own Spring Boot properties. This is highly recommended, as it allows type-safe configuration of the application, as well as auto-completion and documentation within an IDE.

JHipster has generated a ApplicationProperties class in the config package, which is already preconfigured, and it is already documented at the bottom the application.yml, application-dev.yml and application-prod.yml files. All you need to do is code your own specific properties.


就我而言,我已经在 applicaiton-prod.yml 中设置了属性
application:
redis:
host: vnode1
pool:
max-active: 8
max-idle: 8
max-wait: -1
min-idle: 0
port: 6379
在 ApplicationProperties 类中:
@ConfigurationProperties(prefix = "application", ignoreUnknownFields = false)
public class ApplicationProperties {

public final Redis redis = new Redis();

public Redis getRedis() {
return redis;
}

public static class Redis {

private String host = "127.0.0.1";

private int port = 0;

public String getHost() {
return host;
}

public void setHost(String host) {
this.host = host;
}

public int getPort() {
return port;
}

public void setPort(int port) {
this.port = port;
}

private Pool pool = new Pool();

public void setPool(Pool pool) {
this.pool = pool;
}

public Pool getPool() {
return this.pool;
}

public static class Pool {
private int maxActive = 8;
private int maxWait = -1;

public int getMaxIdle() {
return maxIdle;
}

public void setMaxIdle(int maxIdle) {
this.maxIdle = maxIdle;
}

private int maxIdle = 8;
private int minIdle = 0;


public void setMaxActive(int maxActive) {
this.maxActive = maxActive;
}

public int getMaxActive() {
return maxActive;
}

public int getMinIdle() {
return minIdle;
}

public void setMinIdle(int minIdle) {
this.minIdle = minIdle;
}

public int getMaxWait() {
return maxWait;
}

public void setMaxWait(int maxWait) {
this.maxWait = maxWait;
}
}

}
}
然后我将其用作:
private final ApplicationProperties.Redis redis;
public RedisConfiguration(ApplicationProperties applicationProperties){
redis = applicationProperties.getRedis();
}
例如使用 max-waithost :
this.redis.getPool().getMaxWait();
this.redis.getHost();
希望能帮助到你。

关于jhipster - 在哪里以及如何定义应用程序属性? - JHIpster,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31527868/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com