Switch to tabs, and adjust tabsizing in asciidoctor.

上级 a9c4956f
......@@ -44,7 +44,7 @@ NOTE: Spring Boot doesn't generate code or make edits to your files. Instead, wh
Now you can create a web controller for a simple web application.
`src/main/java/hello/HelloController.java`
[source,java]
[source,java,tabsize=2]
----
include::initial/src/main/java/hello/HelloController.java[]
----
......@@ -55,7 +55,7 @@ The class is flagged as a `@RestController`, meaning it's ready for use by Sprin
Here you create an `Application` class with the components:
`src/main/java/hello/Application.java`
[source,java]
[source,java,tabsize=2]
----
include::complete/src/main/java/hello/Application.java[]
----
......@@ -149,7 +149,7 @@ include::complete/pom.xml[tag=tests]
Now write a simple unit test that mocks the servlet request and response through your endpoint:
`src/test/java/hello/HelloControllerTest.java`
[source,java]
[source,java,tabsize=2]
----
include::complete/src/test/java/hello/HelloControllerTest.java[]
----
......@@ -159,7 +159,7 @@ The `MockMvc` comes from Spring Test and allows you, via a set of convenient bui
As well as mocking the HTTP request cycle we can also use Spring Boot to write a very simple full-stack integration test. For example, instead of (or as well as) the mock test above we could do this:
`src/test/java/hello/HelloControllerIT.java`
[source,java]
[source,java,tabsize=2]
----
include::complete/src/test/java/hello/HelloControllerIT.java[]
----
......
......@@ -11,23 +11,23 @@ import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
System.out.println("Let's inspect the beans provided by Spring Boot:");
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
};
}
};
}
}
......@@ -5,10 +5,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
@RestController
public class HelloController {
@RequestMapping("/")
public String index() {
return "Greetings from Spring Boot!";
}
@RequestMapping("/")
public String index() {
return "Greetings from Spring Boot!";
}
}
......@@ -19,23 +19,23 @@ import org.springframework.test.context.junit4.SpringRunner;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class HelloControllerIT {
@LocalServerPort
private int port;
@LocalServerPort
private int port;
private URL base;
private URL base;
@Autowired
private TestRestTemplate template;
@Autowired
private TestRestTemplate template;
@Before
public void setUp() throws Exception {
this.base = new URL("http://localhost:" + port + "/");
}
@Before
public void setUp() throws Exception {
this.base = new URL("http://localhost:" + port + "/");
}
@Test
public void getHello() throws Exception {
ResponseEntity<String> response = template.getForEntity(base.toString(),
String.class);
assertThat(response.getBody(), equalTo("Greetings from Spring Boot!"));
}
@Test
public void getHello() throws Exception {
ResponseEntity<String> response = template.getForEntity(base.toString(),
String.class);
assertThat(response.getBody(), equalTo("Greetings from Spring Boot!"));
}
}
......@@ -19,13 +19,13 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
@AutoConfigureMockMvc
public class HelloControllerTest {
@Autowired
private MockMvc mvc;
@Autowired
private MockMvc mvc;
@Test
public void getHello() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().string(equalTo("Greetings from Spring Boot!")));
}
@Test
public void getHello() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().string(equalTo("Greetings from Spring Boot!")));
}
}
......@@ -8,17 +8,17 @@ import org.springframework.context.ApplicationContext;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
}
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
}
}
......@@ -5,10 +5,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
@RestController
public class HelloController {
@RequestMapping("/")
public String index() {
return "Greetings from Spring Boot!";
}
@RequestMapping("/")
public String index() {
return "Greetings from Spring Boot!";
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册