[Spring] bean name conflict resolve.

ITWeb/개발일반 2021. 11. 30. 12:17

간단하게는 명시적으로 선언을 해주시면 됩니다.

 

서로 다른 패키지에 같은 이름의 class 가 존재 할 경우 발생 할 수 있습니다.

이런 경우 아래와 같이 선언해 주시면 됩니다.

 

@RestController("cat.RestHealthController")

@Service("cat.service.HealthService")

 

@RestController("cluster.RestHealthController")

@Service("cluster.service.HealthService")

 

:

[Spring] @Autowired vs @RequiredArgsConstructor

ITWeb/개발일반 2021. 11. 30. 10:36

Spring DI 선언에 사용 합니다.

 

[Spring Autowired Annotation]

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/beans/factory/annotation/Autowired.html

 

[Lombok RequiredArgsConstructor Annotation]

https://projectlombok.org/api/lombok/RequiredArgsConstructor.html

 

:

[MySQL] group_concat 사용 시 순서 지정.

ITWeb/개발일반 2021. 11. 29. 18:28

참고문서)

https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html#function_group-concat

 

group by 를 이용해서 특정 컬럼의 value 를 concat 할 경우 해당 테이블의 특정 컬럼으로 순서를 맞춰 줘야 할 경우가 있습니다.

group_concat 함수 내부에 order by 를 이용해서 적용 하시면 됩니다.

 

이렇게 하지 않았을 경우 순서에 대해 보장이 된다고 간혹 착각 할 수 있느데 주의 해서 사용하시기 바랍니다.

 

:

[Java] Snake to Camel 변환

ITWeb/개발일반 2021. 11. 25. 16:46

query parameter 로 넘어온 변수가 snake 로 작성 되어 있어서 이걸 camel 로 받도록 해주고 싶을 때 사용 하면 됩니다.

 

- jackson-databind 패키지에 포함 되어 있습니다.

- domain, model 클래스에 아래와 같이 선언 합니다.

// GET /_cluster/settings?flat_settings=true&master_timeout=30s


@Data
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class SettingsModel {
	private String flatSettings;
    private String masterTimeout;
}

참고용으로 기록 합니다.

 

:

[Elasticsearch] LowLevelRestClient 를 이용한 개발 시 Json 결과 처리

Elastic/Elasticsearch 2021. 11. 25. 14:08

보통 Elasticsearch LLRC 를 이용해서 RESTful API 요청 하게 되면
...중략...
Request request = new Request(...중략...);
Response response = esClient.getRestClient().performRequest(request);
String body = EntityUtils.toString(response.getEntity());
...중략...

String 으로 결과를 받아서 리턴 하게 되는데 이 과정에서 JSON String 변환 시 slash 가 추가 되는 불편함이 있을 수 있습니다.
이걸 해소 하려면
...중략...
String body = EntityUtils.toString(response.getEntity());
JsonNode jsonNode = ObjectMapper.readTree(body);
...중략...
readTree 해서 JsonNode Object 로 변환 한 후 처리 하시면 {}, [] 등 모두 깔끔하게 처리가 가능 합니다.

 

ASIS)

{
	"response": "{ \"alias\": \"henry\" }"
}

{
	"response": "[
    	{ \"alias1\": \"henry\" },
        { \"alias2\": \"jeong\" }
      ]"
}

 

TOBE)

{
	"response": { "alias": "henry" }
}

{
	"response": [
    	{ "alias1": "henry" },
        { "alias2": "jeong" }
      ]
}

 

: