小编Pi5*_*i53的帖子

无法注册 bean“exampleService.FeignClientSpecification”。Bean 已定义且覆盖已禁用

我的假客户端类和应用程序类如下。

@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)

java spring spring-boot spring-cloud-feign

11
推荐指数
2
解决办法
2万
查看次数

使用 Spring boot Rest 转换为 JSON 时,Java LocalDateTime 被转换为整数数组

我的代码如下

@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)

我已经将我的代码与返回正确格式的代码进行了交叉检查。

rest json jackson spring-boot

4
推荐指数
1
解决办法
7925
查看次数

在 Java 8 中使用 Optional 进行多次空检查

我想使用 Java 8 使用多个ifelse语句来简化下面的代码。有没有办法使用一些 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 datetime if-statement optional java-8

2
推荐指数
2
解决办法
275
查看次数