add slfj logger

This commit is contained in:
marcodenisi 2020-06-18 22:41:36 +02:00
parent 3cb402ced7
commit eaf5935589
2 changed files with 14 additions and 10 deletions

View File

@ -1,15 +1,21 @@
package com.baeldung.springbootxml; package com.baeldung.springbootxml;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource; import org.springframework.context.annotation.ImportResource;
@SpringBootApplication @Configuration
@EnableAutoConfiguration
@ImportResource("classpath:beans.xml") @ImportResource("classpath:beans.xml")
public class SpringBootXmlApplication implements CommandLineRunner { public class SpringBootXmlApplication implements CommandLineRunner {
private static final Logger logger = LoggerFactory.getLogger(SpringBootXmlApplication.class);
@Autowired private Pojo pojo; @Autowired private Pojo pojo;
public static void main(String[] args) { public static void main(String[] args) {
@ -17,7 +23,7 @@ public class SpringBootXmlApplication implements CommandLineRunner {
} }
public void run(String... args) { public void run(String... args) {
System.out.println(pojo.getField()); logger.info(pojo.getField());
} }
} }

View File

@ -1,11 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<beans <beans xmlns="http://www.springframework.org/schema/beans"
xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
xmlns:p="http://www.springframework.org/schema/p" http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<bean class="com.baeldung.springbootxml.Pojo"> <bean class="com.baeldung.springbootxml.Pojo">
<property name="field" value="${sample}"></property> <property name="field" value="${sample}"></property>