Home | 简体中文 | 繁体中文 | 杂文 | Search | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 作品与服务 | Email

第 5 章 Spring Boot

目录

5.1. Spring Boot Quick start
5.1.1. pom.xml
5.1.2. Controller
5.2. 运行
5.2.1. Linux systemd
5.3. application.properties
5.3.1. server
5.3.1.1. tomcat
5.3.2. charset
5.3.3. JSON
5.3.4. SMTP 相关配置
5.4. SpringApplication
5.4.1. @SpringBootApplication
5.4.2. @EnableAutoConfiguration
5.4.3. @ComponentScan
5.4.4. CharacterEncodingFilter
5.4.5. 隐藏 Banner
5.4.6. CORS 跨域请求
5.4.7. 列出 Beans
5.5. 编译用于Tomcat的 War
5.6. Properties
5.6.1. Application
5.6.2. spring.profiles.active 参数切换配置文件
5.7. Service
5.8. ViewResolver
5.8.1. application.properties
5.8.2. Application
5.8.3. IndexController
5.8.4. src/main/webapp/WEB-INF/jsp/index.jsp
5.8.5. 集成模板引擎
5.9. Spring boot mongodb
5.9.1. Maven
5.9.2. Application
5.9.3. MongoTemplate
5.9.4. Repository
5.10. Spring boot with MySQL
5.10.1. Maven
5.10.2. Resource
5.10.3. Application
5.10.4. JdbcTemplate
5.10.5. CrudRepository
5.11. Spring boot with Oracle
5.11.1. Maven
5.11.2. application.properties
5.11.3. Application
5.11.4. CrudRepository
5.11.5. JdbcTemplate
5.11.6. Controller
5.12. Spring boot with Email
5.12.1. Maven
5.12.2. Resource
5.12.3. POJO
5.12.4. RestController
5.12.5. Test
5.13. Spring boot with Velocity template
5.13.1. Maven
5.13.2. Resource
5.13.3. Application
5.13.4. RestController
5.13.5. Test
5.14. Logging
5.14.1. 禁止控制台输出日志
5.14.2. 日志输出级别
5.15. Spring boot with Spring security
5.15.1. Maven
5.15.2. Reource
5.15.3. Application
5.15.4. WebSecurityConfigurer
5.15.5. RestController
5.15.6. 测试
5.15.7. Spring + Security + MongoDB
5.15.7.1. Account
5.15.7.2. AccountRepository
5.15.7.3. WebSecurityConfiguration
5.16. Connection and Statement Pooling
5.16.1. org.apache.tomcat.jdbc.pool.DataSource
5.16.2. druid
5.16.3. c3p0 - JDBC3 Connection and Statement Pooling
5.16.4. dbcp2
5.16.5. bonecp
5.16.6. dbcp2
5.17. Spring boot with Scheduling
5.17.1. Application.java
5.17.2. Component
5.17.3. 查看日志
5.18. Spring boot with Cache
5.18.1. Spring boot with Redis
5.18.1.1. maven
5.18.1.2. application.properties
5.18.1.3. Controller
5.18.2. @Cacheable
5.18.2.1. maven
5.18.2.2. Controller
5.19. Session
5.19.1. Redis
5.19.1.1. Maven
5.19.1.2. application.properties
5.19.1.3. Application
5.19.2. 测试 Session
5.19.3. JDBC
5.20. FAQ
5.20.1. application.properties 参考
5.20.2. org.hibernate.dialect.Oracle10gDialect does not support identity key generation
5.20.3. No identifier specified for entity
5.20.4. Could not read document: Invalid UTF-8 middle byte 0xd0
5.20.5. java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
5.20.6. Field javaMailSender in cn.netkiller.rest.EmailRestController required a bean of type 'org.springframework.mail.javamail.JavaMailSender' that could not be found.

注意 1.4.0 无法正常工作,这里使用 1.3.0

5.1. Spring Boot Quick start

5.1.1. pom.xml

		
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>api.netkiller.cn</groupId>
	<artifactId>api.netkiller.cn</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>Skyline</name>
	<description>skylinechencf@gmail.com</description>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.4.0.RELEASE</version>
	</parent>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
	</dependencies>

	<build>
		<sourceDirectory>src</sourceDirectory>
		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.3</version>
				<configuration>
					<source />
					<target />
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>		
		
		

5.1.2. Controller

		
package hello;

import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;

@Controller
@EnableAutoConfiguration
public class SampleController {

    @RequestMapping("/")
    @ResponseBody
    String home() {
        return "Hello World!";
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SampleController.class, args);
    }
}
		
		

测试

curl http://127.0.0.1:8080/
		
comments powered by Disqus