创建项目

1)直接创建springBoot项目

第一个SpringBoot项目(二)
第一个SpringBoot项目(二)
第一个SpringBoot项目(二)
第一个SpringBoot项目(二)
controller是后来添加的
第一个SpringBoot项目(二)
直接运行Application就可以,运行效果:
第一个SpringBoot项目(二)

创建maven项目,添加springBoot依赖

第一个SpringBoot项目(二)
这里packaging必须选择jar而不是war,spring boot项目最终会打成一个jar包而不是war包

pom.xml

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

spring-boot-starter-parent:继承spring boot的相关配置
spring-boot-starter-xxx:代表一个spring boot模块
spring-boot-starter-web:代表web模块,在这个模块中含了许多JAR包

controller

第一个SpringBoot项目(二)
SpringApplication.run:运行spring应用程序
@Controller 用于标记在一个类上,使用它标记的类就是一个SpringMVC Controller 对象。分发处理器将会扫描使用了该注解的类的方法。通俗来说,被Controller标记的类就是一个控制器,这个类中的方法,就是相应的动作。
@RequestMapping是一个用来处理请求地址映射的注解,可用于类或方法上。用于类上,表示类中的所有响应请求的方法都是以该地址作为父路径。比如图一中,跳转到登录页面的路径就是localhost:8080/xxx-war/user/toLogin
@EnableAutoConfiguration:这就是spring boot的核心功能,自动配置。就是根据当前引入的JAR包进行自动配置,比如:
引入了jackson的jar包,那么就会自动配置json转换,所以这里可以使用@ResponseBody
引入了spring boot的web模块,就会自动配置web.xml等与web项目相关的内容,所以这些配置都不需要我们自己配了

报错

1、配置spring boot 项目时parent 引入失败解决方式

解决:1:配置maven镜像,使用国内仓
          2:在pom.xml 加上一段依赖

<repositories>
    <repository>  
        <id>spring-snapshots</id>  
        <url>http://repo.spring.io/libs-snapshot</url>  
    </repository>  
</repositories>  

<pluginRepositories>  
    <pluginRepository>  
        <id>spring-snapshots</id>  
        <url>http://repo.spring.io/libs-snapshot</url>  
    </pluginRepository>  
</pluginRepositories>


解决方式请移步:
https://blog.csdn.net/qq_26369317/article/details/80816098

2、org.apache.maven.archiver.MavenArchiver.getManifest错误
解决:安装插件:

https://otto.takari.io/content/sites/m2e.extras/m2eclipse-mavenarchiver/0.17.2/N/LATEST/


update项目

解决方式请移步
https://www.cnblogs.com/asderx/p/6541945.html
参考资料:
https://blog.csdn.net/wangb_java/article/details/70186209

相关文章: