我的假客户端类和应用程序类如下。
@FeignClient(name = "ExampleService", configuration = FeignClientConfig.class, url = "http://localhost:8091")
public interface ExampleClient {
@GetMapping(value = "exampleService/exampleDetails/{id}")
public List<ExampleDTO> getExampleDetails(@PathVariable(name = "id") final Long id);
}
@EnableAutoConfiguration
@EnableScheduling
@SpringBootApplication
@EnableFeignClients(basePackages = {"com.package.example"})
@ComponentScan(basePackages = {"com.package"})
public class ExampleApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(ExampleApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中我收到如下错误
APPLICATION FAILED TO START
Description:
The bean 'ExampleService.FeignClientSpecification' could not be registered. A bean with that name has already been defined and overriding is disabled.
Action:
Consider renaming …Run Code Online (Sandbox Code Playgroud) 我的代码如下
@Data
@Document(collection = "models")
public class Model {
@Field(value = "modelDt")
private LocalDateTime modelDate;
}
@Data
public class ModelDTO {
private LocalDateTime modelDate;
}
@RestController
@RequestMapping("/api/v1/model")
public class ModelController {
@Autowired
ModelService modelService;
@GetMapping
public List<ModelDTO> getModels() {
return modelService.getAllModels();
}
}
Run Code Online (Sandbox Code Playgroud)
几乎在 JSON 响应以正确格式(如 yyyy-mm-ddT00:00:00 )出现的任何地方都使用此方法,但在上面的情况下,我得到以下格式的日期。
[
{
"modelDate": [
YYYY,
MM,
DD,
00,
00,
0000
]
}
]
Run Code Online (Sandbox Code Playgroud)
我已经将我的代码与返回正确格式的代码进行了交叉检查。
我想使用 Java 8 使用多个if和else语句来简化下面的代码。有没有办法使用一些 Java 8 功能来完全摆脱它们,例如Optional?我试图在这里找到一些东西,但找不到答案。
LocalDateTime beDate = someDate;
LocalDateTime aeDate = someDate;
LocalDateTime eDate;
if (beDate == null && aeDate == null) {
eDate = null;
}
else if (beDate != null && aeDate == null) {
eDate = beDate;
}
else if (beDate == null && aeDate != null) {
eDate = aeDate;
}
else if (beDate != null && aeDate != null &&
(beDate.isEqual(aeDate) || beDate.isBefore(aeDate))) {
eDate = …Run Code Online (Sandbox Code Playgroud) java ×2
spring-boot ×2
datetime ×1
if-statement ×1
jackson ×1
java-8 ×1
json ×1
optional ×1
rest ×1
spring ×1