Springboot cannot load
Phenomenon
After the SpringBoot project is started, the log file does not appear in the specified directory.
And the start log starts as follows:
"C:\Program Files\Java\jdk1.8.0_144\bin\java"...
Connected to the target VM, address: '127.0.0.1:52494', transport: 'socket'
18:34:58,011 |-INFO in [default] - Could NOT find resource []
18:34:58,011 |-INFO in [default] - Could NOT find resource []
18:34:58,011 |-INFO in [default] - Found resource [] at [jar:file:/D:/mvn_repo/xxx-1.0.!/]
18:34:58,014 |-INFO in @707194ba - URL [jar:file:/D:/mvn_repo/yyy-1.0.!/] is not of type file
18:34:58,112 |-INFO in - Will scan for changes in [jar:file:/D:/mvn_repo/zzz-1.0.!/]
The file has not been changed, as follows:
<?xml version="1.0" encoding="UTF-8"?> <Configuration status="INFO"> <springProperty scope="context" name="logPath" source=""/> <springProperty scope="context" name="logLevel" source=""/> <appender name="consoleLog" class=""> <layout class=""> <pattern> %d{yyyy-MM-dd HH:mm:} %-5level [%thread] %logger{36} %line - %msg%n</pattern> </layout> </appender> <appender name="fileLog" class=""> <!--Scrolling strategy--> <rollingPolicy class=""> <!--Output path--> <fileNamePattern>${logPath}/server.%</fileNamePattern> </rollingPolicy> <encoder> <pattern> %d{yyyy-MM-dd HH:mm:} %-5level [%thread] %logger{36} %line - %msg%n</pattern> <charset>UTF-8</charset> </encoder> </appender> <appender name="fileErrorLog" class=""> <filter class=""> <level>ERROR</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> <!--Scrolling strategy--> <rollingPolicy class=""> <!--Output path--> <fileNamePattern>${logPath}/server.%</fileNamePattern> </rollingPolicy> <encoder> <pattern> %d{yyyy-MM-dd HH:mm:} %-5level [%thread] %logger{36} %line - %msg%n</pattern> <charset>UTF-8</charset> </encoder> </appender> <root level="${logLevel}"> <appender-ref ref="consoleLog"/> <appender-ref ref="fileLog"/> <appender-ref ref="fileErrorLog"/> </root> </Configuration>
Cause analysis
1. The configuration file location is correct
classes/ ├── ├── com │ └── nero │ └── test │ ├── api │ │ ├──
2. Analyze the startup log, analyze the problem caused by the configuration in the dependency jar, which may be caused by conflicts.
Solution
Add configuration to:
=classpath:
Through this configuration, the configuration file forcing the log is specified, and the problem is solved
springboot configuration, using configurations in different configuration files
spring: profiles: active: prod # active Which configuration file
logging: file: path: d:/var/log
logging: file: path: /var/log/question
<?xml version="1.0" encoding="UTF-8"?> <configuration scan="true" scanPeriod="60 seconds" debug="false"> <contextName>wechat-service</contextName> <!-- !!!!!!!!!Get application-{xxx}.yml Configuration !!!!!--> <springProperty scope="context" name="" source=""/> <!--<property name="" value="log" />--> <property name="" value="15" /> <property name="" value="%d{yyyy-MM-dd HH:mm:ss} | %highlight(%-5level) | %boldYellow(%thread) | %boldGreen(%logger) | %msg%n"/> <property name="" value="%d{yyyy-MM-dd HH:mm:} %contextName [%thread] %-5level %logger{36} - %msg%n" /> <!--Output to console--> <appender name="console" class=""> <encoder> <pattern>${}</pattern> </encoder> </appender> <!--Output to file info Level log--> <appender name="file_info" class=""> <rollingPolicy class=""> <fileNamePattern>${}/info/info.%d{yyyy-MM-dd}.log</fileNamePattern> <MaxHistory>${}</MaxHistory> </rollingPolicy> <encoder> <pattern>${}</pattern> </encoder> <filter class=""> <level>INFO</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> </appender> <!--Output to file error Level log--> <appender name="file_error" class=""> <rollingPolicy class=""> <fileNamePattern>${}/error/error.%d{yyyy-MM-dd}.log</fileNamePattern> </rollingPolicy> <encoder> <pattern>${}</pattern> </encoder> <filter class=""> <level>ERROR</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> </appender> <root level="debug"> <appender-ref ref="console" /> </root> <root level="info"> <appender-ref ref="file_info" /> <appender-ref ref="file_error" /> </root> </configuration>
Get configuration from
<springProperty scope="context" name="" source=""/>
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.