springboot中文文档
https://my.oschina.net/geekidentity/blog/872888java
这里不过多的介绍springboot,直接上步骤,创建一个简单的springboor项目。
工具:
idea(2016.3.4)
jdk(1.8)
maven(3.3.9) git(2.5)
#1.基础工具准备
1.下载安装jdk1.8,百度解决
2.下载maven,配置本地仓库,个人以下
3.下载安装git,这个不是必要,所以后续不介绍这里。
4.下载安装idea。
#2.基础环境配置
打开idea,
1.配置jdk
File-->Project Structure-->Project,而后设置jdk版本。
2.配置maven
File-->Setting,设置以下图
3.配置git
#3.工程搭建
我是采用maven module的形式建立工程,每一个module打成jar包或者war包。
打开idea,
1.建立工程
File-->New-->Project-->左侧Maven选项,以下图
2.建立父级module
File-->New-->Module-->左侧Maven选项,以下图
父级module主要是提供jar包,全部的jar包、maven插件均配置在这里,其它module所须要的jar包、插件均引用这里。以下图
父级pom的配置文件见最下面。
3.建立业务module
通建立父级module步骤同样,只是pom.xml文件配置不一样,以下图
pom配置见最下面。
4.下载maven插件
见下图,
5.启动方式
5.1 main方法启动,Application设置以下
5.2 war包启动
6.启动与请求
#4.结尾
1.cms-project的pom文件git
<?xml version="1.0" encoding="UTF-8"?> <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>cms.test</groupId> <artifactId>cms-project</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> <modules> <module>cms-parent</module> <module>cms-api</module> </modules> </project>
2.cms-parent的pom文件web
<?xml version="1.0" encoding="UTF-8"?> <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> <artifactId>cms-parent</artifactId> <groupId>cms.test</groupId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> <name>cms-parent</name> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.2.RELEASE</version> </parent> <properties> <spring-boot.version>1.5.2.RELEASE</spring-boot.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>${spring-boot.version}</version> </dependency> </dependencies> </dependencyManagement> <build> <pluginManagement> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${spring-boot.version}</version> </plugin> </plugins> </pluginManagement> </build> </project>
3.cms-api的pom文件spring
<?xml version="1.0" encoding="UTF-8"?> <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"> <parent> <artifactId>cms-parent</artifactId> <groupId>cms.test</groupId> <version>1.0-SNAPSHOT</version> <relativePath>../cms-parent</relativePath> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>cms-api</artifactId> <packaging>jar</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
#5.简要讲解
1.@SpringBootApplication注解
该注解开启了Spring组件扫描和自动配置功能,他将以下三个注解组合在一块儿。
1.1spring的@Configuration注解:它是用来管理bean的,等价于xml中配置beans;@Bean标注方法等价于xml中配置bean。以下等价
xml配置apache
<beans> <bean id="class2" class="com.test.Class2"></bean> <bean id="class3" class="com.test.Class3"></bean> </beans>
注解配置以下api
@Configuration public class Class1 { @Bean public Class2 class2(){ return new Class2(); } @Bean public Class3 class3(){ return new Class3(); } }
1.2spring的@ComponentScan注解:扫描注解,以下等价
xml配置springboot
<context:component-scan base-package="com.test">
注解以下maven
@ComponentScan("com.test")
1.3spring的@EnableAutoConfiguration注解:根据classpath自动载入应用程序所需的全部Bean。ide