개발환경에 맞게 프로퍼티 파일 준비
application.properties
application-dev.properties
application-prod.properties
적용할 프로퍼티 지정
spring.profiles.active=dev
java -jar XXX.jar // application.properties 적용됨
java -jar -Dspring.profiles.active=dev XXX.jar // application-dev.properties 적용됨
import java.util.concurrent.TimeUnit;
import org.springframework.http.CacheControl;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class ResourceConfiguration implements WebMvcConfigurer {
@Value("${file.uploadpath}")
String uploadpath;
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler("/img/**")
.addResourceLocations("file://" + uploadpath + "/")
// 접근 파일 캐싱 시간
.setCacheControl(CacheControl.maxAge(1, TimeUnit.MINUTES));
}
}
<!-- log4jdbc -->
<dependency>
<groupId>org.bgee.log4jdbc-log4j2</groupId>
<artifactId>log4jdbc-log4j2-jdbc4.1</artifactId>
<version>1.16</version>
</dependency>
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:xe
spring.datasource.driver-class-name=net.sf.log4jdbc.sql.jdbcapi.DriverSpy
spring.datasource.url=jdbc:log4jdbc:oracle:thin:@localhost:1521:xe
log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
logging.level.jdbc.sqlonly=OFF
logging.level.jdbc.sqltiming=DEBUG
logging.level.jdbc.audit=OFF
logging.level.jdbc.resultset=OFF
logging.level.jdbc.resultsettable=DEBUG
logging.level.jdbc.connection=OFF
import java.util.Map;
import org.apache.ibatis.annotations.Select;
public interface TestMapper {
@Select("select ${col1}, #{col2} as col2 from dual")
public Map<String,Object> test(String col1, String col2);
}
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import com.yedam.app.emp.mapper.TestMapper;
@SpringBootTest
public class TestMapperClient {
@Autowired TestMapper testMapper;
@Test
public void tes() {
String col = "scott";
Map<String, Object> map = testMapper.test("sysdate", col);
assertEquals(col, (String)map.get("col"));
}
}
import org.springframework.context.annotation.Bean;
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.WebSecurityCustomizer;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public PasswordEncoder bcryptPassword() {
return new BCryptPasswordEncoder();
}
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests((requests) -> requests.antMatchers("/home", "/").permitAll().antMatchers("/admin/**")
.hasAuthority("ROLE_ADMIN")
//.anyRequest().authenticated()
.anyRequest().permitAll()
)
.formLogin(login -> login.defaultSuccessUrl("/home").loginPage("/login").usernameParameter("userid")
.permitAll())
.logout().logoutUrl("/logout").logoutSuccessUrl("/home").permitAll()
// .and()
// .csrf().disable();
;
return http.build();
}
@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
return (web) -> web.ignoring().antMatchers("/images/**", "/js/**", "/css/**");
}
}
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>3.0.5</version>
</dependency>
@Configuration
public class JasyptConfig {
@Bean(name = "jasyptStringEncryptor") // 복호화할 때 사용할 빈
public StringEncryptor stringEncryptor() {
String jasyptkey = System.getenv("jasyptkey");
final String key = jasyptkey;
PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
SimpleStringPBEConfig config = new SimpleStringPBEConfig();
config.setPassword(key);
config.setAlgorithm("PBEWithMD5AndDES");
config.setPoolSize("1");
encryptor.setConfig(config);
return encryptor;
}
}
public class JasyptTest {
@Test
public void testpass(){
String encodedPass = encPass("db");
System.out.println(encodedPass);
}
public String encPass(String rawPass){
String jasyptkey = System.getenv("jasyptkey"); //암호화할 때 사용할 키는 실행할 때 외부에서 주입
StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
standardPBEStringEncryptor.setAlgorithm("PBEWithMD5AndDES");
standardPBEStringEncryptor.setPassword(jasyptkey);
String encodedPass = standardPBEStringEncryptor.encrypt(rawPass);
return encodedPass;
}
}
jasypt.encryptor.bean=jasyptStringEncryptor
db.username=ENC(X3XXXX==)
db.password=ENC(eGXXXX==)
name: jasyptkey value: 사용할 키