spring

spring 기술

spring 구조

application.yml

data:
	url-cleancode-batch: http://cleancode-batch:15670
containers:
	- args:
	  env:
		  - name: CLEANCODE_URL
		    valueFrom:
			    configMapKeyRef:
				    key: url-cleancode-batch
				    name: environment
				    optional: false

cloud:
	protocol: https
	domain: ${cloud.protocol}://api.cleancode.kr
	api:
		v2:
			cost_job_call: ${cloud.domain}/cost-analysis/data/sync

crawling


라이브러리 활용

@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Bean {
}
@Bean
public PasswordEncoder passwordEncoder() {
	return new BCryptPasswordEncoder();
}
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Indexed
Public @interface Component {
}
@Component
@RequiredArgsConstructor
publc class CustomAuthManager implements AuthenticationManager {
}

filter


security

protected void doFilterInternal() {
HttpServletRequest request, HttpServletResponse response, FilterChain filterChain
} throws ServletException, IOException {
	String jwt = resolveToken(request);
	if(request.getRequestURI().contains(”/public”)) {
		filterChain.doFilter(request, response);
		return;
	}
	..
	if(StringUtils.hasText(jwt)) {
		try {
			Authentication jwtAuthenticationToken = new JwtAuthenticationToken(jwt);
		} catch (AuthenticationException authException) {
			SecurityContextHolder.clearContext();
		} catch (CertificateException | ParseException e) {
			throw new RuntimeException e;
		}
	}
	filterChain.doFilter(request, response);
}
public securityFilterChain filterChain(HttpSecurity http) throws Exception {
	http.csrfdisable; // 보안 관련 필터 등록설정
	http.authorizeHttpRequests( // 권한 관련 필터 등록과 설정
		auth -> auth
			.requestMatchers(”/api/v2/**”).permitAll()
			.requestMatchers(”/open-api/**”).permitAll()
			//.addFilterBefore(jwtTokenFilter, AuthorizationFilter.class) // 커스텀 필터 등록
			.anyRequest().authenticated()
	);
	http
		.oauth2Login(oauth2 -> oauth2
			.loginPage(”api/v2/tokenLogin”)
		);
	http
		.exceptionHandling(exceptionHandlingConfigurer -> exceptionHandlingConfigurer
		.accessDeniedHandler(jwtAccessDeniedHandler)
		.authenticationEntryPoint(jwtAuthenticationEntryPoint)
		);
	return http.build();
}

transactional


singleton

public static BatchTimeUtil getInstance(BatchInfoMapper batchInfoMapper) {
	if(batchTimeUtil == null) {
		synchronized (BatchTimeUtil.class) {
			if(batchTimeUtil == null) {
				batchTimeUtil = new BatchTimeUtil(batchInfoMapper);
			}
		}
	}
	return batchTimeUtil;
}

api 호출

public ResponseEntity<Object> getMongoManagementPost(String url, Object postParam) {
	//serPassSSL();
	RestTemplate restTemplate = new RestTemplate();
	HttpHeaders headers = new HttpHeaders();
	Headers.set(”Content-Type”, “application/json”);

	return restTemplate.exchange(url, HttpMethod.Post, new HttpEntity<>(postPrams, headers), Object.class);

}
public Flux<T> getMongoManagementService(String url, object postPrams) {

	return WebClient.create()
		.get()
		.uri(uri)
		.retrieve()
		.bodyToFlux(T.class);
} 
private void serPassSSL() {
	try {
		TrustManager[] trustAllCerts = new TrustManager[] {
			new X509TrustManager() {
				public X509Certificate[] getAcceptedIssuers() {return null;}
				public void checkClientTrusted(X509Certificate[] certs, String authType){}
				public void checkServerTrusted(X509Certificate[] certs, String authType){}
			}
		};
		SSLContext sc = SSLContext.getInstance(”SSL”);
		sc.init(null, trustAllCerts, new java.security.SecureRamom());
		HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
	}catch (NoSuchAlgorithmException | KeyManagementException e) {
		throw new RUntimeException(e.getMessage());
	}
}

application 환경변수

@Profile(”dev”)
@Compoenet
Public final class ApiHidden {
	Public static final boolean hidden = true;
}

@Hidden
@PostMapping(”/board”)
@ApiOperation(value=“게시판“, notes=“게시판”, hidden=ApiHidden.hidden)
<Controller method example>

스레드-동시성-경쟁상태

AtomicBoolean.compareAndSet(expected, true)
```