728x90
반응형
SpringBoot는 application.properties를 외부 프로퍼티를 이용해서 실행할 수 있다.
jar 실행방법
java -jar spring-boot.jar
프로퍼티의 이름을 바꿔서 실행할 경우(spring.config.name)
java -jar spring-boot.jar --spring.config.name=./bootStrap.properties
프로퍼티의 location을 지정해줄 경우
ava -jar board-0.0.1-SNAPSHOT.jar --spring.config.location=./config/
config 폴더 아래에있는 프로퍼티 파일을 찾아서 실행한다.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.1)
2021-01-27 16:17:20.832 INFO 30242 --- [ main] com.example.board.BoardApplication : Starting BoardApplication using Java 11.0.9 on baejisukui-MacBookPro.local with PID 30242 (/Users/baejisuk/Documents/workspace/board/out/production/classes started by baejisuk in /Users/baejisuk/Documents/workspace/board)
2021-01-27 16:17:20.837 INFO 30242 --- [ main] com.example.board.BoardApplication : No active profile set, falling back to default profiles: default
2021-01-27 16:17:22.427 INFO 30242 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-01-27 16:17:22.530 INFO 30242 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 82 ms. Found 1 JPA repository interfaces.
2021-01-27 16:17:23.438 INFO 30242 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-01-27 16:17:23.450 INFO 30242 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-01-27 16:17:23.450 INFO 30242 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.41]
2021-01-27 16:17:23.628 INFO 30242 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-01-27 16:17:23.629 INFO 30242 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2565 ms
2021-01-27 16:17:23.786 INFO 30242 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2021-01-27 16:17:23.974 INFO 30242 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2021-01-27 16:17:23.981 INFO 30242 --- [ main] o.s.b.a.h2.H2ConsoleAutoConfiguration : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:d2546045-7b68-4550-a046-1109b5a139aa'
2021-01-27 16:17:24.333 INFO 30242 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-01-27 16:17:24.375 INFO 30242 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.25.Final
2021-01-27 16:17:24.488 INFO 30242 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2021-01-27 16:17:24.607 INFO 30242 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2021-01-27 16:17:25.150 INFO 30242 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2021-01-27 16:17:25.160 INFO 30242 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2021-01-27 16:17:25.774 WARN 30242 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2021-01-27 16:17:26.088 INFO 30242 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-01-27 16:17:26.634 INFO 30242 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-01-27 16:17:26.649 INFO 30242 --- [ main] com.example.board.BoardApplication : Started BoardApplication in 6.601 seconds (JVM running for 7.356)
기존 IDE에서 실행할 때 8080으로 뜨던 서비스
설정파일을 생성해서 8081 포트로 바꾼 후 jar가 있는 폴더에 config를 생성하고 application.properties를 추가했다.
b@MacBookPro libs % java -jar board-0.0.1-SNAPSHOT.jar --spring.config.location=./config/
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.1)
2021-01-27 16:20:28.204 INFO 30374 --- [ main] com.example.board.BoardApplication : Starting BoardApplication using Java 11.0.9 on baejisukui-MacBookPro.local with PID 30374 (/Users/baejisuk/Documents/workspace/board/build/libs/board-0.0.1-SNAPSHOT.jar started by baejisuk in /Users/baejisuk/Documents/workspace/board/build/libs)
2021-01-27 16:20:28.214 INFO 30374 --- [ main] com.example.board.BoardApplication : No active profile set, falling back to default profiles: default
2021-01-27 16:20:30.078 INFO 30374 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-01-27 16:20:30.219 INFO 30374 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 126 ms. Found 1 JPA repository interfaces.
2021-01-27 16:20:31.785 INFO 30374 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8081 (http)
2021-01-27 16:20:31.813 INFO 30374 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-01-27 16:20:31.813 INFO 30374 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.41]
2021-01-27 16:20:32.030 INFO 30374 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-01-27 16:20:32.031 INFO 30374 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3677 ms
2021-01-27 16:20:32.183 INFO 30374 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2021-01-27 16:20:32.413 INFO 30374 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2021-01-27 16:20:32.424 INFO 30374 --- [ main] o.s.b.a.h2.H2ConsoleAutoConfiguration : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:342e8972-1f6e-459e-ad81-579907cbeefa'
2021-01-27 16:20:32.967 INFO 30374 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-01-27 16:20:33.070 INFO 30374 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.25.Final
2021-01-27 16:20:33.484 INFO 30374 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2021-01-27 16:20:33.706 INFO 30374 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2021-01-27 16:20:34.975 INFO 30374 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2021-01-27 16:20:34.987 INFO 30374 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.boot.loader.jar.Handler (file:/Users/baejisuk/Documents/workspace/board/build/libs/board-0.0.1-SNAPSHOT.jar) to constructor sun.net.www.protocol.jar.Handler()
WARNING: Please consider reporting this to the maintainers of org.springframework.boot.loader.jar.Handler
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2021-01-27 16:20:36.058 WARN 30374 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2021-01-27 16:20:36.447 INFO 30374 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-01-27 16:20:37.009 INFO 30374 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8081 (http) with context path ''
2021-01-27 16:20:37.033 INFO 30374 --- [ main] com.example.board.BoardApplication : Started BoardApplication in 9.974 seconds (JVM running for 10.859)
java -jar spring-boot.jar --spring.config.additional-location=./config/
additional-location프로퍼티로 파일을 추가할 경우 기본 위치에 추가되서 사용된다.
추가위치는 기본 위치보다 먼저 검색된다.
기본 위치의 검색순서는
> file :/config/
> file:./
> classpath:/config/
> classpath:./
인데 만약 additional-location으로 ./add-config/를 추가하면
> file:./add-config/
> classpath:/add-config/
> file :/config/
> file:./
> classpath:/config/
> classpath:./
순서대로 검색한다.
728x90
반응형
'Spring' 카테고리의 다른 글
Spring Boot QR코드 이미지 생성 해서 thymeleaf로 보여주기 (0) | 2021.12.16 |
---|---|
resilience4j circuit breaker test (with spring boot) (0) | 2021.04.09 |
Netflix Zuul Gateway Filter (0) | 2021.01.16 |
SpringBoot @Conditional 에 대해 알아보자 (0) | 2021.01.09 |
SpringBoot @EnableEncryptableProperties 스프링에서 암호화를 써보자 (0) | 2021.01.08 |