SpringBoot学习——初始环境搭建

1、首先创建Maven项目,请参考https://blog.csdn.net/mahoking/article/details/80312461。

 

2、本例的开发工具为STS4,即Spring Tool Suite 4 。编写pom.xml文件,本例使用的Spring Boot的版本为2.2.5.RELEASE。


  4.0.0
  com.mahaochen.learn.boot
  LearnBoot
  0.0.1-SNAPSHOT
  
 	
        org.springframework.boot
        spring-boot-starter-parent
        2.2.5.RELEASE
    
    
    	UTF-8
        UTF-8
    	1.8
  	
    
    
    	
			org.springframework.boot
        	spring-boot-starter-web
    	
    	
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
        
        	org.mybatis.spring.boot
    		mybatis-spring-boot-starter
    		1.1.1
        
        
        	mysql
        	mysql-connector-java
        	
        
        
        	org.springframework.boot
        	spring-boot-devtools
        	true
    	
    
    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    

3、编写application.yml文件,该文件位于/src/main/resources/application.yml。

#指定启动端口
server:
  address: 127.0.0.1
  port: 9001
  servlet:
    context-path: /LearnBoot
#MyBatis配置
mybatis:
  config-location: classpath:config/mybatis/mybatis-config.xml
  mapper-locations: classpath:config/mybatis/mapper/*.xml
#MySQL配置
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/learnapp?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8
    username: root
    password: root

:由于Spring Boot的版本为2.2.5.RELEASE,默认使用最新的MySQL驱动,所以driver-class-name: com.mysql.cj.jdbc.Driver。

4、编写Spring Boot启动类LearnBootAppliaction。

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@MapperScan("com.mahaochen.learn.boot.mapper")
public class LearnBootAppliaction {

	public static void main(String[] args) throws Exception {
		SpringApplication.run(LearnBootAppliaction.class, args);
	}

}

:@MapperScan(package),扫描MyBatis接口。

 

你可能感兴趣的:(Spring,Boot,知识分享)