The background,
Recently, in the process of transforming a SpringBoot monomer architecture project into a SpringCloud microservice project, application. Yml was transformed into Bootstrap. yml in order to use nacOS configuration center and at the same time to make the local development environment independent of NACOS. Yml is also changed to bootstrap-dev.yml.
The initial environment configuration file structure is as follows:
Logback. XML does not take effect
After the microservice transformation is completed, the local development environment logback. XML does not take effect, and the most obvious feature is that the configured SQL printing is missing, while many environments on the server use the configuration in the NACOS configuration center. Logback configuration is normal, and so is SQL printing.
3. Problem analysis and positioning
3.1 Guess logback.xml is a problem
XML in bootstrap-dev.yml does not take effect, so I changed the name of logback. XML to logback-spring. XML because springCloud supports logback-spring. The problem was not solved, so logback.xml was ruled out.
3.2 Guess is the problem of bootstrap.yml
Yml is a system-level configuration, while application. Yml is an application-level configuration. Bootstrap. yml is loaded earlier. Therefore, springcloud uses bootstrap.yml to load the nacos-related configuration, and then reads the application.yml configuration in the configuration center through the nacos configuration in bootstrap.yml. Normal logback.xml is configured in application.yml. Logback. XML does not support loading using bootstrap.yml. Therefore, the local development environment re-adds the application.yml configuration file and turns nacOS off in bootstrap.yml. After testing, the local SQL can print normally.
The configuration file structure is as follows:Bootstrap. yml configuration:
spring: application: name: cbam-monitor-task cloud: nacos: discovery: enabled: false server-addr: The ${NACOS_HOST: 127.0.0.1} : ${8848} NACOS_PORT: # namespace: ${NACOS_NAME_SPACE:2b6e230c-de4e-4005-af5f-1ee07dc45a74} config: enabled: false server-addr: ${spring.cloud.nacos.discovery.server-addr} namespace: ${NACOS_NAME_SPACE:2b6e230c-de4e-4005-af5f-1ee07dc45a74} group: ${NACOS_GROUP:TG} file-extension: ymlCopy the code
Configure logbacks in application.yml
logging:
config: classpath:log/logback.xml
Copy the code
Four, conclusion
Bootstrap. yml does not support the logback. XML or logback-spring. XML configuration. The logback. Bootstrap. yml is used as a bootstrap configuration to configure only nacOS-related configurations.