# 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
โ - springboot-jpa - springboot-lecture โ