spring 에서 async기능구현 필요가 있다면 메쏘드에 @Async를 사용하면 된다.

이 때, Application에는 @EnableAsync가 필요하다.


 REF



Retryable은 몇번의 실패을 다시 해주게 해주는데, 아래와 같이 사용하면된다.

정해진 실패 회수를 초과할 경우 @Recover함수가 불리게 되는데, exception + 파라미터가 동일하다는 점에 주의! 


Application에는  @EnableRetry가 필요하다.  


private static final int MAX_ATTEMPTS = 4;
private static final long BACK_OFF_DELAY = 2000;  //msec
@Retryable(value = DataAccessResourceFailureException.class,
maxAttempts = MAX_ATTEMPTS,
backoff = @Backoff(delay = BACK_OFF_DELAY))
public void checkAndProcess(String userKey, String itemId) {

@Recover
public void recover(DataAccessResourceFailureException e, String userKey, String itemId) {
log.error("All retries have failed!, userKey:{} " + e.toString(), userKey);
}


Posted by yongary
,

reflection

java core 2017. 4. 12. 10:03

private 함수를 테스트 할 경우, java의 reflection기능을 사용해서 test할 수 있다.


import java.lang.reflect.Method;


Map<String, Long> repeatMap = null;
try {
Method method = ChatRankingService.class.getDeclaredMethod("getRepeatCount", List.class);
method.setAccessible(true);
repeatMap = (Map<String, Long>)method.invoke(chatRankingService, serviceCodes);
} catch (Exception e) {
}

이와 같이 method.setAccessible(true)를 하면 private함수도 실행이 가능하다. 

Posted by yongary
,

REF



oracle에서 workbench를 다운로드 해서( GPL 라이선스라 로그인은 필요함)

실행한 후, 


Database메뉴에서 

 => Reverse Engineering을 하면, 




기존시스템의 ERD를 뽑을 수 있게 된다.



Posted by yongary
,

화면의 table 에 이미 있는 내용을 사용자가 또 추가입력하는 경우

(즉, 팝업을 통해서 새로운 데이타를 추가하는데,  화면에 이미 있는내용과 중복되는지 체크하는 경우)


서버를 통하지 않고, jQuery를 통해서 쉽게 방지해서 alert창을 뛰울 수 있다.






<script type="text/javascript"> function nameCheck() { var name = $('#myInput').val();

if ($('.listedName:contains(' + name + ')').length != 0) {
alert('already Exists');
return false;
}
return true;
} </script>



<table>
<tr>
<td>ID1</td>
<td class="listedName">name1</td> // name2, name3 등 반복

</tr>


.....

<form onsubmit="'return nameCheck()'">

<input id="myInput"/>


그런데, contains함수가 문제가 약간있다.

Entity단위(테이블 TD단위)로 비교를 하지 않고...    Entity안에 단어가 포함되는지를 비교하는 문제가 있다.


그래서  정확하게 비교를 하고 싶을때는 filter를 쓸 필요가 있다.  REF


if ($('.listedName').filter(function() {
return $(this).text() === name;
}).length !=0 ) {


Posted by yongary
,

RestTemplte.getForEntity 등 각종 함수에서 RestClientException (RUNTIME Exception)을 throw한다.


하지만 이 에러는 code를 표시하지 않기 때문에,


HttpClientErrorException을 catch하는게 좋다.




Class HttpClientErrorException

이렇게 HttpClientErrorException은 RestClientException을 상속받으며, 우리가 http를 주로사용하기 때문에

대부분이 여기에 해당된다.


사용법은 REF 첫번째 answer과 같이... 사용하면 된다.


try {
        ResponseEntity<StoreDto> r = restTemplate.getForEntity(url, StoreDto.class, m);
    }
    catch (final HttpClientErrorException e) {
        System.out.println(e.getStatusCode());
        System.out.println(e.getResponseBodyAsString());
    }


404에러 등이 잡힌다. 


Posted by yongary
,


spring에서 이전페이지로 복귀는 request의 referer를 이용해서 가능하다.


이전 페이지에 추가적인 데이타를 보내고 싶다면

addFlashAttribute로 가능하다. 


import javax.servlet.http.HttpServletRequest;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

String myFunction(HttpServletRequest request,
RedirectAttributes redirectAttributes,
) {

redirectAttributes.addFlashAttribute("okList", "AA BB CC");

String referer = request.getHeader("Referer");
return "redirect:"+ referer;
}


Posted by yongary
,

MEAN, LAMP & Others

IT 2017. 3. 16. 18:30

LAMP stack: Linux, Apache, MySql, PHP (Perl/Python)

  REF

MEAN stack: MongoDB, ExpressJS, AngularJS, NodeJS

         - ExpressJS:  Node.js Web application framework. 

         - NodeJS: event-driven I/O server-side JavaScript Environment.




Play-framework :  Scala & java 용 프레임워크.  REF

- 이게 spring처럼 널리 이용된다면 scala도 그만큼 역량을 키워가겠네요.  

- JSON과 xml을 First-class 고객으로 모시는 프레임워크인만큼 계속 영향력이 커지지 않을까요..










Posted by yongary
,

bootstrap을 이용해서 table도 쉽고 이쁘게 만들 수 있지만

팝업도 간단히 이쁘게 만들 수 있다.


게다가 팝업이 약간씩 멋지게 움직이는 효과도 있어 심미적으로 만족감도 상당하다.


팝업은 modal ( 팝업이 뜨면서 팝업안에서만 작업이 되는 팝업을 일컫는 단어) 을 이용하면 되고

팝업이 나타나면서 움직이는 효과는 aria-hidden을 이용하면 된다..  REF



bootstrap.min.css  LINK 및 

bootstrap.min.js 정도추가하면 되고.. 및


modal DIALOG의 구조는 아래와 같은 구조.

<div class="modal fade" role="dialog" aria-hidden="true">

<div class="modal-dialog" role="document">
<div class="modal-content">

<div class="modal-header">
<div class="modal-body"> 
<div class="modal-footer">



TEXT Color

<p class="text-muted">...</p> //grey
<p class="text-primary">...</p> //light blue
<p class="text-success">...</p> //green
<p class="text-info">...</p> //blue
<p class="text-warning">...</p> //orangish,yellow
<p class="text-danger">...</p> //red


Posted by yongary
,

웹상에서 간단히 날짜 선택창을 만들고 싶다면

jQuery의 DatePicker모듈을 이용하는 것이 좋아 보인다.


REF   (우측 상단에 예제 있음)



TimePicker도 시간입력용으로 좋은데,

시간을 step단위로 지정이 가능하다.  REF


var timeFix;

function timeFixClick(minutes) {
timeFix.val(minutes);
$('#timeModal').modal('show');
}

$(document).ready(function () {
timeFix = $('#timeFix');

datePicker.datepicker({
format: "yyyy-mm-dd",
viewMode: "days",
minViewMode: "days",
});

timePicker.timepicker();
timePicker.timepicker('option', 'step', '30'); //30분 단위로 시간 선택가능.

<html>

<input name="expireTime" class="form-control" data-time-format="H:i:s" id="timePicker" type="text" size="8" />
<a th:onclick="'javascript:timeFixClick(\'' + ${ticket.minutes} + '\');'" th:text="修正" />



<js 시간 Library> -   REF: https://momentjs.com/



  <script type="text/javascript" th:src="@{js/moment.min.js}"></script>  한 후에..


(사용 예)

  var date = moment(dateData).format('YYYY-MM-DD');

  var time = moment(dateDate).format('HH:mm:ss');


Posted by yongary
,

Jms + ActiveMQ

Spring 2017. 3. 13. 16:34

spring에서 msg를 전달하는 가장 흔한 방법은

JMS(+jmsTemplate)과 ActiveMQ(by apache)를 이용하는 방법이다. 물론 ASYNC 메시징이다.


ActiveMQ를 사용하고자 하면, ActiveMQConnectionFactory가 JMSConnectionFactory로써 제공된다.


 -디폴트 포트: 61616 



<Send>

ConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616";

Connection conn = cf.createConnection();


session = conn.createSession(..);


MessageProducer producer = session.createProducer(destination);


producer.send( session.createTextMessage('hello')..)




<Receive>

MessageConsumer consumer = session.createConsumer(destination);
Message message = consumer.receive();



<JmsTemplate을 사용하면 좀더 간단해진다>


jmsOperations.send( new MessageCreator() { ......blabla }

또는 컨버팅 필요시

 

jmsOperations.convertAndSend


Posted by yongary
,