Spring

(Example) Disable spring security default login page

๋ฌธ์ œ

spring security ๊ด€๋ จ ๋””ํดํŠธ ๋กœ๊ทธ์ธ ํŽ˜์ด์ง€ ํ™”๋ฉด์ด ๊ณ„์† ๋œธ

์›์ธ

SecurityConfig ํด๋ž˜์Šค๊ฐ€ Configuration์œผ๋กœ ๋“ฑ๋ก๋˜์ง€ ์•Š์•„ ํ”„๋กœ์ ํŠธ์—์„œ ์„ค์ • ์ธ์‹์„ ๋ชปํ•จ

ํ•ด๊ฒฐ

@Configuration๊ณผ @EnableWebSecurity ์–ด๋…ธํ…Œ์ด์…˜ ์ถ”๊ฐ€

์ฝ”๋“œ

package net.schoolvery.schoolveryserver.global.security;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .httpBasic().disable()
                .cors().and().csrf().disable();
    }
}

reference

DB ์ปฌ๋Ÿผ๋ช…์— underbar ์žˆ์œผ๋ฉด JPA ์ฟผ๋ฆฌ ์ธ์‹ ๋ชปํ•˜๋Š” ๋ฌธ์ œ

โœ”๏ธ ๋ฌธ์ œ

mysql์— ๋งž์ถฐ ์นด๋ฉœ ์ผ€์ด์Šค๋กœ ์ปฌ๋Ÿผ๋ช… ํ†ต์ผํ–ˆ๋Š”๋ฐ(user_name),

DB ์ปฌ๋Ÿผ๋ช…์— ์–ธ๋”์Šค์ฝ”์–ด๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ findByUser_name(ํ˜น์€ findByUserName) ๋ชป์”€

๐Ÿ™‡๐Ÿป ํ•ด๊ฒฐ

@Column์˜ต์…˜์— ์ปฌ๋Ÿผ ๋„ค์ž„์€()์„ ์ง€์ •ํ•ด์ฃผ๊ณ , ํ”„๋กœ๊ทธ๋žจ ์•ˆ์—์„œ๋Š”

@Column(name = "service_name")
String serviceName;

reference

java.lang.NullPointerExceptioin

Gradle's dependency cache may be corrupt

  • compileQuerydsl ์˜ค๋ฅ˜

reference

h2 console ์•ˆ๋ณด์ž„

BaseEntity null๊ฐ’ ๋“ค์–ด

์›์ธ

JPA Auditing

ํ•ด๊ฒฐ

์•„๋ž˜ ์ฝ”๋“œ ์ถ”๊ฐ€

@EnableJpaAuditing

reference

Cannot deserialize value of type java.time.LocalDateTime from String

Querydsl setting error

๋ฐฐ๊ฒฝ

๊ฒ€์ƒ‰ ์ฒ˜๋ฆฌ๋ฅผ ํ†ตํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๊ธฐ ์œ„ํ•ด QueryDSL ํ”„๋ ˆ์ž„์›Œํฌ ์ ์šฉ

๋ฌธ์ œ

build.gradle์˜ dependencies์— ์ถ”๊ฐ€ํ•˜๊ณ  ์‹คํ–‰์ค‘

Unable to load class 'com.mysema.codegen.model.Type'. ๋œธ

์›์ธ

QueryDsl์€ ๊ธฐ์กด dependency๋“ค์„ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒฝ์šฐ์™€ ๋‹ค๋ฅด๊ฒŒ ์„ค์ •ํŒŒ์ผ๋“ค์„ ์ถ”๊ฐ€ํ•ด์ฃผ์–ด์•ผ ํ–ˆ์Œ .. ใ… 

ํ•ด๊ฒฐ

//build.gradle 

// 1) ์ถ”๊ฐ€
buildscript {
	ext {
		queryDslVersion = "5.0.0"
	}
}

...

// 2) plugin ์ถ”๊ฐ€
plugins {
	id 'org.springframework.boot' version '2.6.6'
	id 'io.spring.dependency-management' version '1.0.11.RELEASE'
	id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
	id 'java'
}

...

// 3) ํŒŒ์ผ ์ƒ์„ฑ ๊ฒฝ๋กœ ์ถ”๊ฐ€
def querydslDir = "$buildDir/generated/querydsl"

querydsl {
	jpa = true
	querydslSourcesDir = querydslDir
}

sourceSets {
	main.java.srcDir querydslDir
}

configurations {
	querydsl.extendsFrom compileClasspath
}

compileQuerydsl {
	options.annotationProcessorPath = configurations.querydsl
}

reference

Querydsl cannot find symbol ์—๋Ÿฌ

๋ฌธ์ œ

Q class ์ž์ฒด๊ฐ€ ์ƒ์„ฑ์ด ์•ˆ๋˜๊ณ , ๋นŒ๋“œํ•  ๋–„ ๋‹น์—ฐํžˆ Q class ์ฐธ์กฐ ๋ชปํ•จ

์›์ธ

JWT util ํŒŒ์ผ(repository ์™ธ์˜ ์ฝ”๋“œ)์—์„œ ์˜ค๋ฅ˜๊ฐ€ ์ƒ๊ฒจ ๋นŒ๋“œํ•  ๋•Œ Q class ์ƒ์„ฑ์ด ์•ˆ๋จ

ํ•ด๊ฒฐ

๋ฒ„๊ทธ ์žˆ๋Š” ๋ถ€๋ถ„์„ ํ•ด๊ฒฐ ํ•˜๊ณ  ๋‹ค์‹œ ๋นŒ๋“œํ•˜๋‹ˆ Q class ์ƒ์„ฑ !!!

reference

Table 'DBNAME.TableName' doesn't exist.

ERROR 1074 (42000) at line 3: Column length too big for column 'txt' (max = 21845); use BLOB or TEXT instead

์›์ธ

์ปฌ๋Ÿผ value ๋„ˆ๋ฌด ์ปค์„œ ๋ชป๋“ค์–ด๊ฐ

ํ•ด๊ฒฐ

column value ์ค„์—ฌ์ฃผ๋‹ˆ๊นŒ ๋“ค์–ด๊ฐ

reference

Request method 'POST' not supported

[org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported]

์›์ธ

postman์—์„œ requestbody ๋ณด๋‚ผ๋•Œ, ์ฒ˜์Œ์— row์—์„œ application type์ด text๋กœ ๋˜์–ด์žˆ์—ˆ์Œ

ํ•ด๊ฒฐ

json์œผ๋กœ ๋ฐ”๊ฟ”์คŒ

์ฃผ์˜

๊ฐ€๋” postman์—์„œ url ์ฃผ์†Œ๋ž‘ ๋ฉ”์†Œ๋“œ ์ž˜๋ชป๋งค์น˜ํ•ด์„œ 404? ๋œธ ! ใ…‹ใ…‹ ์ฃผ์˜์ฃผ์˜

What is the difference between @Controller and @RestController

Spring์—์„œ ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ์ง€์ •ํ•ด์ฃผ๊ธฐ ์œ„ํ•œ ์–ด๋…ธํ…Œ์ด์…˜์€ @Controller์™€ @RestController๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ์ „ํ†ต์ ์ธ Spring MVC์˜ ์ปจํŠธ๋กค๋Ÿฌ์ธ @Controller์™€ Restuful ์›น์„œ๋น„์Šค์˜ ์ปจํŠธ๋กค๋Ÿฌ์ธ @RestController์˜ ์ฃผ์š”ํ•œ ์ฐจ์ด์ ์€ HTTP Response Body๊ฐ€ ์ƒ์„ฑ๋˜๋Š” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค. ์ด๋ฒˆ์—๋Š” 2๊ฐ€์ง€ ์–ด๋…ธํ…Œ์ด์…˜์˜ ์ฐจ์ด์™€ ์‚ฌ์šฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

@RestController๋Š” @Controller์— @ResponseBody๊ฐ€ ์ถ”๊ฐ€๋œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋‹น์—ฐํ•˜๊ฒŒ๋„ RestController์˜ ์ฃผ์šฉ๋„๋Š” Json ํ˜•ํƒœ๋กœ ๊ฐ์ฒด ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ตœ๊ทผ์— ๋ฐ์ดํ„ฐ๋ฅผ ์‘๋‹ต์œผ๋กœ ์ œ๊ณตํ•˜๋Š” REST API๋ฅผ ๊ฐœ๋ฐœํ•  ๋•Œ ์ฃผ๋กœ ์‚ฌ์šฉํ•˜๋ฉฐ ๊ฐ์ฒด๋ฅผ ResponseEntity๋กœ ๊ฐ์‹ธ์„œ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ์ด์œ ๋กœ ๋™์ž‘ ๊ณผ์ • ์—ญ์‹œ @Controller์— @ReponseBody๋ฅผ ๋ถ™์ธ ๊ฒƒ๊ณผ ์™„๋ฒฝํžˆ ๋™์ผํ•ฉ๋‹ˆ๋‹ค.

reference

  • ์•„ ์ด๊ฑฐ pathch-< put?

Cannot determine value type from string

  • db update

reference

Access to DialectResolutionInfo be null when 'hibernate.dialect' not set

reference

java.lang.IllegalStateException: org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing

MYSQL)Data too long for column ์—๋Ÿฌ ํ•ด๊ฒฐ

Last updated