Spring Boot + Mybatis + Spring MVC环境配置(一) :Spring Boot初始化,依赖添加

最近在搭建一个Spring Boot + Mybatis + Spring MVC的环境,折腾来折腾去,两三天才搞定,记录下大概过程和遇到的错误

看一下Spring Boot官方的介绍 http://spring.io/projects/spring-boot   :

Spring Boot + Mybatis + Spring MVC环境配置(一) :Spring Boot初始化,依赖添加_第1张图片

Spring Boot让开发者省去了大多数Spring的配置,让其只需要关注主要的开发和进行少量的Spring配置。

嵌入了Tomcat,已定义好大多数的依赖关系,简化了项目的构建配置。我们在使用的时候不用关心框架之间的兼容性,适用版本等问题,想使用的东西,仅仅添加一个配置就可以了,所以使用spring boot非常适合构建微服务。


第一步,访问 https://start.spring.io/  生成一个spring boot项目

Spring Boot + Mybatis + Spring MVC环境配置(一) :Spring Boot初始化,依赖添加_第2张图片


生成之后会下载一个压缩包,解压后,在Eclipse中Import为Maven项目


第二步,添加额外需要的依赖,如Mybatis

pom.xml内容如下:



	4.0.0
	com.kai
	demo
	0.0.1-SNAPSHOT
	jar
	demo
	Demo project for Spring Boot
	
		org.springframework.boot
		spring-boot-starter-parent
		2.0.4.RELEASE
		 
	
	
		UTF-8
		UTF-8
		1.8
	
	
		
			org.springframework.boot
			spring-boot-starter
		
		
			org.springframework.boot
			spring-boot-starter-test
			test
		
		
			org.springframework.boot
			spring-boot-starter-web
		
		
			org.springframework.boot
			spring-boot-devtools
			true
		
		
		
			mysql
			mysql-connector-java
		
		
			org.mybatis
			mybatis
			3.4.6
		
		
			org.mybatis
			mybatis-spring
			1.3.2
		
		
			org.apache.logging.log4j
			log4j
			2.11.1
			pom
		
		
			org.springframework
			spring-jdbc
		
		
			com.zaxxer
			HikariCP
			3.2.0
		
	
	
		
			
				org.springframework.boot
				spring-boot-maven-plugin
				
					true
				
			
		
	


引入web模块

Spring Boot Web Starter

Starter for building web, including RESTful, applications using Spring MVC. Uses Tomcat as the default embedded container


        org.springframework.boot
        spring-boot-starter-web
 

pom.xml文件中默认有两个模块:

spring-boot-starter:核心模块,包括自动配置支持、日志和YAML;

spring-boot-starter-test:测试模块,包括JUnit、Hamcrest、Mockito。


开发环境的调试

热启动在正常开发项目中已经很常见了吧,虽然平时开发web项目过程中,改动项目启重启总是报错;但springBoot对调试支持很好,修改之后可以实时生效,需要添加以下的配置:


    
        org.springframework.boot
        spring-boot-devtools
        true
   


    
        
            org.springframework.boot
            spring-boot-maven-plugin
            
                true
            
        
   

完整环境下载地址: https://github.com/CatherineHu/Spring-Boot-Mybatis-MVC  


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10314474/viewspace-2200331/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10314474/viewspace-2200331/

你可能感兴趣的:(Spring Boot + Mybatis + Spring MVC环境配置(一) :Spring Boot初始化,依赖添加)