在父级项目的pom文件上面加说以下内容:
<build>
<finalName>${project.artifactId}</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
然后直接在父级的项目或是pom文件右击选择install进行整个项目的打包即可。
=================转载内容===============
目录
一、简介
二、搭建一个基本的web-mvc 项目
2.1 Configure environment
2.2 Start
official document:http://projects.spring.io/spring-boot/
项目代码: https://github.com/Ryan-Miao/springboot-test
一、简介
SpringMVC是非常伟大的框架,开源,发展迅速。优秀的设计必然会划分、解耦。所以,spring有很多子项目,比如core、context、bean、mvc等。这对知根底的人来说很简单明了,然而springmvc就是为了傻瓜式的操作而发明的。对于初学springmvc的人来说,想要入手就开发需要拷贝一连串的dependency而不知道这个是干嘛,不知道是不是少了依赖。像我刚接触springmvc的时候到处百度教程而发现各有不同,于是复制了一个又一个代码却不能自己设置,根本原因是不了解各个依赖的包。
Spring-Boot 正是为了解决繁复的代码配置而产生的。Spring-Boot 也是基于java-base 开发的代码,及不用xml文件配置,所有代码都由java来完成。还可以加入Groovy的动态语言执行。
本文只是Springboot的初始化用法,更多详情,参阅[Java Web 之 Springboot](http://www.cnblogs.com/woshimrf/p/java-web-springboot.html)
二、搭建一个基本的web-mvc 项目
2.1 Configure environment
- java 1.8+
- maven 3.3+
- spring-boot 1.3.5
- idea 15
- Thymeleaf 3
2.2 Start
在idea中,选择new-》maven创建一个空的maven项目,比如名字springboot-test。
2.2.1pom.xml
设定java版本:
1 2 3 |
|
添加依赖版本管理dependencyManagement
1 2 3 4 5 6 7 8 9 10 11 12 |
|
添加spring-web项目依赖
1 2 3 4 5 6 7 8 9 10 11 |
|
添加build-plugin
1 2 3 4 5 6 7 8 9 10 11 12 |
|
如此,一个简单的restful的webservice的项目就搭建好了。如果想要支持视图渲染,即jsp、freeMark、velocity等,添加对应的依赖即可。比如,我使用Thymeleaf模板:
1 2 3 4 |
|
2.2.2 创建java代码
如果新建项目的名字是:springboot-test. 则创建包springboot-test/src/main/java/com/test.
com
+- example
+- myproject
+- Application.java
|
+- domain
| +- Customer.java
| +- CustomerRepository.java
|
+- service
| +- CustomerService.java
|
+- web
+- CustomerController.java
com.test是我们的基本包名。下面创建配置类com.test.AppConfig。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
@SpringBootApplication 标注启动配置入口,可以发现通过一个main方法启动。使用这个注解的类必须放置于最外层包中,因为默认扫描这个类以下的包。否则需要自己配置@ComponentScan。
这样,配置基本完成了。下面开发控制层controller:
创建com.test.controller.HelloController。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
创建视图代码:
视图默认放在springboot-test\src\main\resources\templates**.
所以创建springboot-test\src\main\resources\templates\index.html
1 2 3 4 5 6 7 8 9 10 |
|
D:\workspace\springboot\springboot-test\src\main\webapp\hello.html
1 2 3 4 5 6 7 8 9 10 11 |
|
2.2.3 run
启动方式多种,可以启动main方法,也可以通过命令行启动:
View Code
浏览器访问:localhost:8080/index
关注我的公众号