何らかの形でLogbackは印刷されませんが、System.out.printlnはSpringApplication.runの後にあります。私は、コンテキストで読み込まれたBeanを出力しようとしています。もちろん、私はSystem.outでそれを行うことができます。しかし、私は日誌でそれをしたいと思います。誰も私が下のコードで紛失しているものを説明することができますか?SpringApplication.runの後にログバックが出力されない
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
@SpringBootApplication
public class MyApplication {
final static Logger logger = LoggerFactory.getLogger(MyApplication.class);
public static void main(String[] args) {
// This works fine. I am using logback behind the slf4j api.
logger.debug("Hello world from Spring Boot.");
ApplicationContext appContext = SpringApplication.run(
MyApplication.class, args);
// The system.out works all right. The debug does not. Why?
logger.debug("Let's inspect the beans provided by Spring Boot:");
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = appContext.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
}
}
/pom.xml
<groupId>fun.and.games</groupId>
<artifactId>learnspringboot</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<!-- mvn -e clean install exec:java -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<mainClass>fun.and.games.MyApplication</mainClass>
</configuration>
</plugin>
<!-- Configure the project to use java 8 version. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<!-- Disable annotation processing for ourselves. -->
<compilerArgument>-proc:none</compilerArgument>
</configuration>
</plugin>
<!-- mvn -e clean install spring-boot:run -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
のsrc /メイン/リソース/ application.properties
logging.level.root=DEBUG
でロギングレベルの詳細を確認してください
「Spring BootからのHello World」印刷されます。したがって、ログバックが見つからない場合はありません。おもう。コードを実行する時間がありましたか?この公開要旨にはすべてのコードが含まれています。 https://gist.github.com/kaunjovi/b336886f319533f443cfbac1ec081abe –
plzあなたのポールやグラデーションを見せてください。 –