어플리케이션의 민감정보를 한 곳에서 관리하는 spring에서 제공하는 모듈
homebrew를 통해 설치
brew install vault
vault 서버를 아래 명령어로 시작하자(토큰 id 00~은 기본 default 비밀번호이다)
$ vault server --dev --dev-root-token-id="00000000-0000-0000-0000-000000000000"
아래 문자열이 보이면 vault 서버가 정상적으로 시작된것이다.

위의 명령어로 vault 서버 시작 시, 개발 모드로 인메모리를 사용 하여 암호화 되지 않은 민감정보를 전달한다. 이 방식은 vault 서버를 로컬에서 테스트 용으로 사용하기 적절하다. 만약 운영에서 사용 시 SSL인증서나 해당 IP만 접근하도록 설정이 필요하다.
프록시 객체를 통해 기존 객체를 수정하지 않고 타겟 객체에 대한 접근을 제어하며, 프록시 객체에 부가 기능을 추가할 수 있었다. 하지만 타겟 클래스의 수만큼 프록시 객체를 만드는 번거로움이 있었다.
이러한 번거로움은 동적 프록시 기술로 해결할 수 있다. JDK에서 제공하는 JDK동적 프록시 기술이나 오픈 소스인 CGLIB를 활용하면 프록시를 적용할 코드만 생성 후 필요한 곳에 적용할 수 있다.
💡 리플랙션동적 프록시 기술에 적용되었으며, 리플랙션을 통해 클래스나 메서드의 메타정보를 읽어 코드를 조작할 수 있다.

프록시 객체를 호출한다. call()
public class JdkDynamicProxyTest {
public static void main(String[] args) {
AInterface target = new AImpl();
TypeInvocationHandler handler = new TypeInvocationHandler(target);
AInterface proxy
= (AInterface) Proxy.newProxyInstance(AInterface.class.getClassLoader(), new Class[]{
AInterface.class},handler);
**proxy.call();**
System.out.println("target.getClass() = " + target.getClass());
System.out.println("proxy.getClass() = " + proxy.getClass());
}
}
JDK동적 프록시가 InvocationHandler.invoke()를 호출한다.
InvocationHandler는 JDK 동적 프록시 규약이므로 구현해야한다.
proxy : 프록시 자기 자신
method : 호출한 메서드
Object[] args : 메서드 호출할 때 전달할 인수
public class TypeInvocationHandler implements InvocationHandler {
private final Object target;//프록시 적용 대상
public TypeInvocationHandler(Object target) {
this.target = target;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
System.out.println("TypeInvocation Handler 실행");
long startTime = System.currentTimeMillis();
Object result = **method.invoke(target, args);**
long resultTime = System.currentTimeMillis() - startTime;
System.out.println("resultTime = " + resultTime);
return result;
}
}
TypeInvocationHandler 에 정의된 프록시의 부가적인 로직을 수행하고, method.invoke()를 호출하여 target(AImpl)을 호출한다. invoke 메서드의 파라미터로 AInterface에 명시된 call()가 넘겨진다.
public interface AInterface {
String call();
}
Begin Transaction
Execute several queries
Commit the transaction[참고]
https://spring.io/guides/gs/vault-config/