springboot + lombok을 이용한 간단한 rest api를 만들던 중

 

@Builder
@ToString
public class ResponseDto {
    @Builder.Default private boolean success = false;
    private String title;
    @Singular private List<String> contents;
}
ResponseDto.builder()
                    .success(true)
                    .title("title")
                    .content("1")
                    .content("2")
                    .content("3")
                    .build();
{ 
  "success": true, 
  "title": "title", 
  "contents": [ 
    "1", 
    "2", 
    "3"
  ] 
}

와 같은 결과를 기대했으나..

HttpMessageNotWritableException 에러가 발생했다.

 

jackson-databind, core를 dependency를 추가해서 해결하란 답이 가장 많았으나

class에 @Getter추가함으로 해결

'개발 > Spring boot' 카테고리의 다른 글

[Spring Boot] spring-boot-admin-starter-server 적용  (0) 2020.03.04

spring boot admin server 를 적용해보자

 

1. spring boot 프로젝트 생성시 spring web만 추가해서 생성.

2. pom.xml에 dependency 추가

<dependency>
	<groupId>de.codecentric</groupId>
	<artifactId>spring-boot-admin-starter-server</artifactId>
	<version>2.1.6</version>
</dependency>

 

3. @EnableAdminServer 애노테이션 추가

@SpringBootApplication
@EnableAdminServer
public class AdminServerApplication {

	public static void main(String[] args) {
		SpringApplication.run(AdminServerApplication.class, args);
	}

}

 

 

4. 어플리케이션 실행

	at de.codecentric.boot.admin.server.web.servlet.AdminControllerHandlerMapping.registerHandlerMethod(AdminControllerHandlerMapping.java:44) ~[spring-boot-admin-server-2.1.6.jar:2.1.6]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.registerHandlerMethod(RequestMappingHandlerMapping.java:78) ~[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at de.codecentric.boot.admin.server.web.servlet.AdminControllerHandlerMapping.registerHandlerMethod(AdminControllerHandlerMapping.java:44) ~[spring-boot-admin-server-2.1.6.jar:2.1.6]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.registerHandlerMethod(RequestMappingHandlerMapping.java:78) ~[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at de.codecentric.boot.admin.server.web.servlet.AdminControllerHandlerMapping.registerHandlerMethod(AdminControllerHandlerMapping.java:44) ~[spring-boot-admin-server-2.1.6.jar:2.1.6]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.registerHandlerMethod(RequestMappingHandlerMapping.java:78) ~[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at de.codecentric.boot.admin.server.web.servlet.AdminControllerHandlerMapping.registerHandlerMethod(AdminControllerHandlerMapping.java:44) ~[spring-boot-admin-server-2.1.6.jar:2.1.6]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.registerHandlerMethod(RequestMappingHandlerMapping.java:78) ~[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at de.codecentric.boot.admin.server.web.servlet.AdminControllerHandlerMapping.registerHandlerMethod(AdminControllerHandlerMapping.java:44) ~[spring-boot-admin-server-2.1.6.jar:2.1.6]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.registerHandlerMethod(RequestMappingHandlerMapping.java:78) ~[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at de.codecentric.boot.admin.server.web.servlet.AdminControllerHandlerMapping.registerHandlerMethod(AdminControllerHandlerMapping.java:44) ~[spring-boot-admin-server-2.1.6.jar:2.1.6]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.registerHandlerMethod(RequestMappingHandlerMapping.java:78) ~[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at de.codecentric.boot.admin.server.web.servlet.AdminControllerHandlerMapping.registerHandlerMethod(AdminControllerHandlerMapping.java:44) ~[spring-boot-admin-server-2.1.6.jar:2.1.6]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.registerHandlerMethod(RequestMappingHandlerMapping.java:78) ~[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at de.codecentric.boot.admin.server.web.servlet.AdminControllerHandlerMapping.registerHandlerMethod(AdminControllerHandlerMapping.java:44) ~[spring-boot-admin-server-2.1.6.jar:2.1.6]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.registerHandlerMethod(RequestMappingHandlerMapping.java:78) ~[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at de.codecentric.boot.admin.server.web.servlet.AdminControllerHandlerMapping.registerHandlerMethod(AdminControllerHandlerMapping.java:44) ~[spring-boot-admin-server-2.1.6.jar:2.1.6]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.registerHandlerMethod(RequestMappingHandlerMapping.java:78) ~[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at de.codecentric.boot.admin.server.web.servlet.AdminControllerHandlerMapping.registerHandlerMethod(AdminControllerHandlerMapping.java:44) ~[spring-boot-admin-server-2.1.6.jar:2.1.6]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.registerHandlerMethod(RequestMappingHandlerMapping.java:78) ~[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE]

 

에러가난다 구글링 해보다가 발견한 이슈. 버전문제인가?

https://github.com/codecentric/spring-boot-admin/issues/1054

 

java.lang.NoSuchMethodError: reactor.retry.Retry.retryMax(J)Lreactor/retry/Retry · Issue #1054 · codecentric/spring-boot-admin

error with spring cloud Finchley.RC2 + spring boot admin 2.1.1

github.com

 

5. 스프링 버전 다운

2.2.5에서 2.1.13으로 변경하니 오류없이 실행이 된다.

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.1.13.RELEASE</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>

 

 

버전참고. https://spring.io/projects/spring-boot#learn

'개발 > Spring boot' 카테고리의 다른 글

HttpMessageNotWritableException 에러 발생 시  (0) 2020.05.10

+ Recent posts