我有一个简单的 Spring Boot API 项目,当我在本地计算机上执行可启动 jar 文件或 Google Kubernetes Engine 上的 docker 映像时,该项目运行良好,但在docker run本地计算机上使用时会发出错误。我像这样构建并执行了图像:
docker build -t foo .
docker run -p 8080:8080 -e SPRING_PROFILES_ACTIVE=local foo
Run Code Online (Sandbox Code Playgroud)
这是错误:
Logging system failed to initialize using configuration from 'null'
java.lang.IllegalStateException: Logback configuration error detected:
ERROR in ch.qos.logback.core.joran.spi.Interpreter@15:14 - RuntimeException in Action for tag [appender] java.lang.IllegalArgumentException: A project ID is required for this service but could not be determined from the builder or the environment. Please set a project ID using the …Run Code Online (Sandbox Code Playgroud) 首先,我想解释一下我所创造的Hierarchical REST API和的含义。Normalized REST API
http://www.example.com/customers/12345/orders)customer包含an order)
http://www.example.com/customers/12345{
"name": "John Doe",
"orders": [{
"id": 1,
"price": 10,
"delivered": true
}, {
"id": 2,
"price": 11,
"delivered": false
}
]
}
Run Code Online (Sandbox Code Playgroud)
http://www.example.com/customers/12345/ordershttp://www.example.com/customers/12345/orders/1http://www.example.com/customers/12345/orders?accepted=truehttp://www.example.com/customershttp://www.example.com/customers?firstName=Johnhttp://www.example.com/customers/12345http://www.example.com/orders/1http://www.example.com/customers/12345{
"name": "John Doe",
"orderIds": [1, 2]
}
Run Code Online (Sandbox Code Playgroud)
我认为这两种方法都有各自的优点和缺点
http://www.example.com/customers/12345)有没有办法在中间实体(映射表)中使用@OneToMany和过滤软删除的多对多关联@ManyToOne?
product并且product_option_group是 N:M 关系。我正在使用该disabled_datetime列实现软删除,并希望ProductOptionGroup从Product实体中过滤一个集合。这篇文章正在使用@ManyToMany并@Where实现这一目标。我跟着,它工作(禁用product_option_groups 被过滤)。需要注意@Where的ProductOptionGroup类。
// `product` <-> `product-product_option_group` <-> `product_option_group`
@Entity
@Table(name = "product")
public class Product implements Serializable {
...
@ManyToMany
@JoinTable(name = "product-product_option_group",
joinColumns = @JoinColumn(name = "product_id"),
inverseJoinColumns = @JoinColumn(name = "product_option_group_id"))
private final Set<ProductOptionGroup> productOptionGroups = new HashSet<>();
...
}
@Entity
@Table(name = "product_option_group")
@Where(clause = "disabled_datetime is null")
public …Run Code Online (Sandbox Code Playgroud) 例如,
package com.spring.app;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
/**
* Handles requests for the application home page.
*/
@Controller
public class HomeController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(final Model model) {
model.addAttribute("msg", "SUCCESS");
return "hello";
}
}
Run Code Online (Sandbox Code Playgroud)
我想使用JUnit 来测试model其属性及其值home().我可以改变返回类型以ModelAndView使其成为可能,但我想使用String它因为它更简单.但这不是必须的.
无论如何都要检查model而不改变home()返回类型?或者它无法帮助?
变量的名称可以更改,不应影响逻辑.但是name()Enum中的方法返回一个常量名称作为值,因此它可以破坏现有代码.我应该避免使用name()吗?
例如,
public enum Example1 {FOO, BAR}
Run Code Online (Sandbox Code Playgroud)
重构FOO名称FOO2将制动Example1.FOO.name().equals("FOO").
public enum Example2 {
FOO("FOO"),
BAR("BAR");
String code;
private Example2(final String code) {
this.code = code;
}
public String getCode() {
return code;
}
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,更改FOO名称FOO2将不会制动Example2.FOO.getCode().equals("FOO").
我正在为“在首尔运行的 E2 实例核心”付费。账单报告显示相关服务是“Compute Engine”,但没有从 Compute Engine 运行的虚拟机实例。我无法追踪账单的原因。
不确定是否相关,但我创建了 4 个 Cloud Run 服务,具有 0 个最小实例自动扩展设置,每天运行时间可能为 0~5 分钟。但“在首尔运行的E2实例核心”的使用量是7天84小时。所以我认为这不是原因。
为什么我要为“在首尔运行的 E2 实例核心”付费?
google-compute-engine google-cloud-platform google-cloud-billing
我正在尝试读取这样的 yml 文件。
order:
foo: 5000
bar: 12
Run Code Online (Sandbox Code Playgroud)
我可以用 来阅读它@value。(顺便说一句,我正在使用龙目岛)
@Component
@Data
public class WebConfigProperty {
private Integer foo;
private Integer bar;
public WebConfigProperty(@Value("${order.foo}") @NonNull final Integer foo,
@Value("${order.bar}") @NonNull final Integer bar) {
super();
this.foo = foo;
this.bar = bar;
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用,@ConfigurationProperties因为 yml 文件会变得更加复杂。但它不适用于@ConfigurationProperties.
@Component
@ConfigurationProperties("order")
@Data
public class WebConfigProperty {
@NonNull
private Integer foo;
@NonNull
private Integer bar;
}
Run Code Online (Sandbox Code Playgroud)
我还添加@EnableConfigurationProperties了一个配置类。配置中的所有注释都是这样的。
@SpringBootConfiguration
@EnableConfigurationProperties
@EnableAutoConfiguration(exclude = { ... })
@ComponentScan(basePackages = …Run Code Online (Sandbox Code Playgroud) spring ×3
java ×2
spring-boot ×2
annotations ×1
docker ×1
dockerfile ×1
enums ×1
hibernate ×1
javabeans ×1
jpa ×1
junit ×1
logback ×1
rest ×1
soft-delete ×1
spring-mvc ×1
unit-testing ×1
uri ×1
url ×1
yaml ×1