spring boot(1)

建立spring boot 项目

工具 idea

输入图片说明

@SpringBootApplication至关于@Configuration、@EnableAutoConfiguration和 @ComponentScan,你也能够同时使用这3个注解。其中@Configuration、@ComponentScan是spring框架的语法,在spring 3.x就有了,用于代码方式建立配置信息和扫描包。@EnableAutoConfiguration是spring boot语法,表示将使用自动配置。你若是下载了spring boot源码,就会看到spring boot实现了不少starter应用,这些starter就是一些配置信息(有点相似于docker,一组环境一种应用的概念),spring boot看到引入的starter包,就能够计算如何自动配置你的应用。html

pom文件

<?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>com.fsd.java</groupId>
	<artifactId>hcadmin</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>hcadmin</name>
	<description>Demo project for Spring Boot</description>

	<!-- spring boot基本环境 -->
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.5.6.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<!--web应用基本环境配置 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
<!--   html模板引擎 start-->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency>
		<dependency>
			<groupId>net.sourceforge.nekohtml</groupId>
			<artifactId>nekohtml</artifactId>
		</dependency>
		<!--   html模板引擎 end-->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>

<!-- Spring boot提供的一些开箱即用的应用很是容易使用,好比监控,你只须要在pom文件中引入: 引入以后,spring boot是默认开启监控的,运行应用你能够在浏览器中输入:  http://localhost:8080/health-->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>

	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>


</project>

具体搭建过程,在这里再也不赘述,idea很强大,能够下载试试java

启动 部署 spring boot应用

能够直接运行main函数,web

使用maven工具 打包 或者使用ide工具提供的 maven project 里面的 package 右键spring

 

 要部署运行spring boot应用,首选要打包spring boot应用,你在pom文件中看到的spring-boot-maven-plugin插件就是打包spring boot应用的。docker

进入工程目录运行mvn package,如:apache

  D:\项目路径> mvn package浏览器

  打包事后就能够进入target目录使用java原生命令执行这个应用了。框架

  D:\工程项目路径下\target>java -jar 刚才上一步产生的名字-0.0.1.jarmaven

  如此,你就看到一个基于jar包的web应用启动了。ide

至此 spring boot 项目简单应用到此就能够运行了,欢迎指导交流