Java/Spring Boot(71)
-
Spring boot static method에서 @Autowired field를 호출해야 하는 경우
static method에서 @Autowired field를 호출하면 null 에러가 발생함해결하기 위해서 해당 class의 생성자에 @Auowired를 기술함# @Autowired를 쓰기 위해서 필요함@Componentpublic class Util { # static으로 설정 private static UtilService utilService; # @Autowired로 지정 @Autowired public Util(UtilService utilService) { # this가 아닌 Util로 호출 Util.utilService = utilService; } public static String test(String type, String value) { String res..
2024.08.13 -
Spring boot 정적 파일 위치 셋팅
기본 위치/resources/static/resources/public설정 변경spring: mvc: static-path-pattern: /** web: resources: static-locations: "classpath:/static/"
2024.08.11 -
Spring boot access log 설정
Log 생성 위치Local: {프로젝트 Dir}/logsServer: {jar 파일이 있는 Dir}/logs설정application.yml에 적용server: tomcat: basedir: . accesslog: enabled: true pattern: '%{yyyy-MM-dd HH:mm:ss}t %s %r %{User-Agent}i %{Referer}i %a %b'
2024.08.11 -
객체를 json으로 변환해서 보내기
# data.put에 들어가는 값이 null이면, json 결과에서 제외 됨# targetUrl = null이면, response에 referer가 빠짐response.setContentType("application/json;charset=UTF-8");response.setStatus(HttpServletResponse.SC_OK);JSONObject data = new JSONObject();data.put("success", true);data.put("msg", "테스트 성공!!");data.put("referer", targetUrl);PrintWriter writer = response.getWriter();writer.print(data);writer.flush();
2024.08.03 -
because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
response 결과가 '302'로 나옴css 파일이 존재하지만, Spring boot Security에서 로그인 예외처리를 하지 않아서 접근이 안되는 문제환경설정에서 예외 처리를 해줘야 함@Configuration@EnableWebSecuritypublic class WebSecurityConfig { @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http.authorizeHttpRequests((requests) -> requests .requestMatchers("/", "{css 디렉토리}/*.css").permitAll() .anyRequest().authenticat..
2024.07.18 -
Spring boot에 sencha app 생성
spring boot project에 static 디렉토리 생성sencha app 생성# workspace 생성cd {sprinb boot project directory}/src/main/resources/staticsencha generate workspace .# app 생성sencha -sdk {sencha directory} generate app {sencha proejct name}spring boot project에서 static 디렉토리 refresh확인localhost:{port}/index.html
2024.07.13