JAVA-2419: Move/rename module spring-boot-xml
This commit is contained in:
@@ -5,3 +5,4 @@ This module contains articles about Spring Boot customization 2
|
||||
### Relevant Articles:
|
||||
|
||||
- [DispatcherServlet and web.xml in Spring Boot](https://www.baeldung.com/spring-boot-dispatcherservlet-web-xml)
|
||||
- [XML Defined Beans in Spring Boot](https://www.baeldung.com/spring-boot-xml-beans)
|
||||
@@ -23,7 +23,10 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.springbootxml;
|
||||
|
||||
public class Pojo {
|
||||
|
||||
private String field;
|
||||
|
||||
public Pojo() {
|
||||
}
|
||||
|
||||
public String getField() {
|
||||
return field;
|
||||
}
|
||||
|
||||
public void setField(String field) {
|
||||
this.field = field;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.baeldung.springbootxml;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.ImportResource;
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@ImportResource("classpath:beans.xml")
|
||||
public class SpringBootXmlApplication implements CommandLineRunner {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SpringBootXmlApplication.class);
|
||||
|
||||
@Autowired private Pojo pojo;
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringBootXmlApplication.class, args);
|
||||
}
|
||||
|
||||
public void run(String... args) {
|
||||
logger.info(pojo.getField());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
sample=string loaded from properties!
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
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
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<bean class="com.baeldung.springbootxml.Pojo">
|
||||
<property name="field" value="${sample}"></property>
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.baeldung.springbootxml;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = SpringBootXmlApplication.class)
|
||||
public class SpringBootXmlApplicationIntegrationTest {
|
||||
|
||||
@Autowired private Pojo pojo;
|
||||
@Value("${sample}") private String sample;
|
||||
|
||||
@Test
|
||||
public void whenCallingGetter_thenPrintingProperty() {
|
||||
assertThat(pojo.getField())
|
||||
.isNotBlank()
|
||||
.isEqualTo(sample);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user