이전 수업에서는 구성없이 아이디어 도구를 통해 SpringBoot 프로젝트를 구축했으며 성공적으로 시작되었지만 실제 프로젝트의 요구를 충족시키는 것과는 거리가 멀다는 것이 분명합니다. 예를 들어, 우리는 자체 Redis 구성, MySQL 구성 등을 소개하려고합니다. 어떻게 처리해야합니까? Spring MVC에서는 모두 Spring.xml 관련 파일을 통해 구성합니다. SpringBoot에는 더 이상 존재하지 않습니다. 어떻게 구성해야합니까? 걱정하지 마세요. 모든 사람에게 즉시 답변을 설명해 봅시다.
no1. 프로젝트를 할 때 많은 환경을 구별 할 수 있습니까? 예를 들어, 개발 환경, 테스트 환경, 생산 환경 등의 첫 번째 단계는 각 환경을 구성하게됩니다.
1. 먼저 프로젝트의 pom.xml 파일을 열고 다음 내용을 추가하십시오.
<빌드> <FinalName> $ {project.artifactID}-$ {project.version} </finalName> <플러그인> <Plugin> <groupId> org.springframework.boot </groupId> <artifactID> Spring-Boot-Maven-Plugin </artifactId> <execution> <Goal Goal </Goal> </GOALT> </executions> </plugin> <plugin> <groupId> org.apache.maven.maven.plugins </groupid> <artifactid> maven-compiler-plugin </artifactid> <bersion> 3.3 </version> <configuration> <source> 1.8 </source> </target> <condf8 </spigp8 </spigit> </plugins> <filters> <filter> <filter> Src/Main/Resources/Application- $ {Filter-Resource-Name} .Properties </필터> </filters> <Resource> <Resource> <bersore> <eriversory> <directory> src/main/resources </directory> <filtering> <exclud> </*filters/*<독점> <독점> <pextude> applicate-dev.properties </exclude> <exclude> application-test.properties </exclude> <pexclude- alpha.properties </exclude> <pexclude> applicate-prod.properties </resource> <resource> <irectory> src/main/resources> <filtering> </filtering> <contenter> <clude> application- $ {Filter-Resource-Name} .Properties </include> </inclend> </resource> </resource> </build> <profiles> <profile> </id> <cluction> <cti성 비드 프레 패션> True </activeBydefault> </activation> <properties> </properce--name> dev </filter-resource-name> </properties> </profile> <profile> <id> 테스트 </id> <properties> <Filter-Resource-Name> 테스트 </필터-자원-이름> </properties> </properties> <propect> <id> alpha </id> <filter-resource-name> alpha </filter-resource-name> <id> prod </id> <properties> <Filter-Resource-name> prod </filter-Resource-name> </properties> </profile> </profiles>나는 모든 사람들 이이 단락에 익숙하다고 생각합니다. 그래서 나는 그것을 많이 설명하지 않을 것입니다 (질문이 있으시면 나에게 개인 메시지를 보내주십시오).
2. 그런 다음 Application.Properties 파일을 열고 다음 내용을 추가하십시오.
# 활성화 된 구성 파일을 나타냅니다 (dev | prod)
spring.profiles.Active =@Filter-Resource-Name@
전체 프로젝트는 다음과 같은 구조가되었습니다.
이 시점에서 SpringBoot 다중 환경 구성이 완료되었습니다.
3. 로그 레벨을 설정하십시오
#log levellogging.level.root = 디버그
4. 사용자 정의 포트 및 인스턴스 이름을 설정하십시오
#port server.port = 8888#인스턴스 이름 spring.application.name = demo-springboot
5. logback-spring.xml
<? xml version = "1.0"alcoding = "utf-8"?> <configuration> <resource = "org/springframework/boot/logging/logback/base.xml"/> <appender name = "demo"> <file> demo/demo.log </file> <RollingPolicy> <! <filenamepattern> demo/demo.%d {yyyy-mm-dd} .log </filenamepattern> <!-가장 큰 로그 기록은 10 일-> <maxhistory> 10 </maxhistory> </rollingpolicy> <utf-8 "> <$ {file_log _pattern}} </appender> <logger name = "com.example.demo"level = "info"addly = "false"> <appender-ref ref = "demo"/</logger> <logger name = "com.example.demo.dao"level = "debug"/> <logger name = "com.example.demo.service" "info" "info" 이름 = "druid.sql.statement"level = "debug" /> <logger name = "druid.sql.statement"level = "debug" /> <logger name = "com.example.demo.service"level = "info" /> <logger name = "druid.sql.statement"레벨 = "로그" 이름 = "druid.sql.resultset"level = "debug" /> <logger name = "org.apache"level = "info" /> <logger name = "org.mybatis.spring"level = "error" /> <logger name = "org.spramework"level = "info"> <gerger name = "springfox"> Level = "info"> <Appender-Ref Ref = "Demo"/> </root> </구성 이 시점에서 프로젝트의 기본 환경 구성이 구축되었습니다. Dev | Test | Prod를 선택하여 Maven Clean Install에서 지정한 구성을 입력 한 다음 응용 프로그램을 실행하십시오. LocalHost : 8888에 액세스 할 수있는 경우 구성에 액세스하고 지정할 수 있습니다. 그러나 이것은 충분하지 않습니다. 프로젝트 개발은 데이터베이스를 운영해야합니다. 하하 예, SpringBoot + MySQL + Mybatis의 세계에 들어 갑시다!
요약
위는 편집자가 소개 한 SpringBoot Multi-Environment Configuration Tutorial입니다. 나는 그것이 당신에게 도움이되기를 바랍니다. 궁금한 점이 있으면 메시지를 남겨 주시면 편집자가 제 시간에 답장을 드리겠습니다. Wulin.com 웹 사이트를 지원해 주셔서 대단히 감사합니다!