# Spring profiles Change

Github๋“ฑ open๋œ ๊ณณ์—์„œ ์†Œ์Šค๋ฅผ ๊ด€๋ฆฌํ•  ๊ฒฝ์šฐ DB ์ •๋ณด์™€ ๊ฐ™์€ ์ค‘์š”์ •๋ณด๋Š” Parameter๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์‹คํ–‰ํ•˜๋„๋ก ํ•˜๋ฉด, ์ •๋ณด ๋ณดํ˜ธ๊ฐ€ ๊ฐ€๋Šฅํ•จ 
* ์ ์šฉ๋ฐฉ๋ฒ•(bootRun ์‹œ VM ์„ธํŒ…์— ์ถ”๊ฐ€)
-Dspring.profiles.active=prod -Dspring.datasource.username=test  -Dspring.datasource.password=test -Dvariables.ip=127.0.0.1 -Dvariables.sid=XE


1. build.gradle

implementation 'org.springframework.boot:spring-boot-configuration-processor'

bootRun {
    systemProperties System.properties
    main = "com.tistory.f5074.spring_boot.Application"
}

2. Application.java
@SpringBootApplication
@MapperScan(value = {"com.tistory.f5074.spring_boot"})
@EnableConfigurationProperties

3. application.yml
spring:
  profiles:
    active: test
  datasource:
    driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
    url: jdbc:log4jdbc:oracle:thin:@${variables.ip}:1521/${variables.sid}
    username: test
    password: test

variables:
  ip: localhost
  sid: xe

# JSP ์„ธํŒ…

1. build.gradle
implementation 'javax.servlet:jstl'
implementation 'org.apache.tomcat.embed:tomcat-embed-jasper'

2. application.yml
spring:
  mvc:
    static-path-pattern: /static/**
    view:
      prefix: /WEB-INF/views/
      suffix: .jsp

3. src/main/webapp/WEB-INF/views/index.jsp
ํ•ด๋‹น๊ฒฝ๋กœ์— ์„ค์ •ํ•ด์ค˜์•ผ jsp ํŽ˜์ด์ง€๊ฐ€ ์ ์šฉ๋จ

# jar ๋ฐฐ์น˜ ์‹คํ–‰ ์‹œ JSP๊ฐ€ ์—ด๋ฆฌ์ง€ ์•Š๋Š” ๋ถ€๋ถ„

jar๋ฅผ war๋กœ ๋ณ€๊ฒฝํ•ด์„œ ๋ฐฐํฌํ•  ๊ฒฝ์šฐ ๊ฐ€๋Šฅ

1. build.gradle
apply plugin: 'war'

bootWar{
    archiveBaseName = 'spring_boot'
    archiveFileName =  'spring_boot.war'
    archiveVersion = '0.0.0'
} 

2. build.gradle์„ ๋ณ€๊ฒฝํ›„ gradle sync ์‹œ ServletInitializer ์ƒ์„ฑ๋จ

3. ๊ธฐ์กด Application.java ์— ๋ฉ”์ธ ๋ฉ”์„œ๋“œ๋ฅผ ServletInitializer๋กœ ๋ณ€๊ฒฝ

@SpringBootApplication
@MapperScan(value = {"com.tistory.f5074.spring_boot"})
@EnableConfigurationProperties
public class ServletInitializer extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }


    public static void main(String[] args){
        SpringApplication.run(ServletInitializer.class,args);
    }

}

4. application.yml ๋ฆฌ์†Œ์Šค์šฉ ํŒŒ์ผ์œ„์น˜

spring: 
  resources:
    static-locations: classpath:/static/
    add-mappings: true

# batch file

vi start_server.sh

---
#!/bin/sh -
nohup java -Dfile.encoding=UTF-8 -jar ./build/drawing-app.war --server.port=8081 > ./drawing-app/app.out 2> ./drawing-app/app.err < /dev/null & nohup echo $! > ./drawing-app/pid.file &
---

vi stop_server.sh
---
#!/bin/sh -
kill $(cat ./drawing-app/pid.file)
---

# Run Configurations

Environment variables: 
-spring.profiles.active=stage;-spring.datasource.url=jdbc:log4jdbc:oracle:thin:@127.0.0.1:1521/XE

# ๋ฐฉํ™”๋ฒฝ ์ž‘์—…ํ›„ postgre SQL๊ด€๋ จ ์—ฐ๊ฒฐ์ด ์•ˆ๋จ

-- connect ์ƒํƒœ ํ™•์ธ ์‹œ ๋ฐฉํ™”๋ฒฝ ์ž‘์—…์ดํ›„ ํ•ด๋‹น ์ปค๋„ฅ์…˜์ด ์—ฐ๊ฒฐ๋˜์ง€ ์•Š์Œ
-- ์„œ๋ฒ„์—์„œ telnet ๋“ฑ์„ ์‚ฌ์šฉํ•ด์„œ ์—ฐ๊ฒฐ์ƒํƒœ๋Š” ์ •์ƒ์ด์—ˆ์Œ
-- ๋ฐฉํ™”๋ฒฝ ์ž‘์—… ํ›„ Java ์„œ๋น„์Šค์—์„œ ์žฌ์—ฐ๊ฒฐ์ด ๋˜์ง€ ์•Š์•„์„œ ๋ฐœ์ƒ


-- postgre ์šด์˜ ์ปค๋„ฅ์…˜ ์ •๋ณด ํ™•์ธ
SELECT usename
	, application_name
	, client_addr
	, client_port
	, backend_start
	, query_start
	, state
	, query
FROM pg_stat_activity
WHERE datname = 'postgres'
	AND client_addr IN ('192.168.0.1', '192.168.0.2')
ORDER BY client_addr DESC
Last Updated: 4/13/2025, 11:14:44 PM