快速的搭建一个基于SpringBoot框架的Maven项目

1.简介

SpringBoot框架最大的有点在于快速开发,快速开发的原理就是SpringBoot中的三大主要配置:

起步依赖,引导类,属性配置文件(两类三种,第一类是application.yaml和application.yml类的配置文件,第二类是application.properties)
1.**起步依赖:**将一个框架所必须的依赖jar包和环境集成,直接引入起步依赖便完成了jar包的引入问题。
2.**引导类:**可直接启动项目
3.**属性配置文件:**可以将数据源,端口。。等信息添加进去,具体的配置方式需要按照要求引入。

2.搭建步骤

2.1 首先先创建一个Maven项目,按照图片的目录结构创建包(Application.java是引导类,引导类必须放在当前项目的根目录下,否则不会出现spring的图标,项目无法启动)controller/service/dao分别是三层架构,util是工具类
在这里插入图片描述

2.2在pom.xml中添加起步依赖

<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.0.1.RELEASE</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>
	<!-- 配置编码 和开发jdk版本 -->
	<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>

		<!-- spring-boot jap web tomcat -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-jpa</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-tomcat</artifactId>
			<!--<scope>provided</scope>-->
		</dependency>

		<!-- mysql -->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<scope>runtime</scope>
		</dependency>

		<!-- 工具类 -->
		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-lang3</artifactId>
		</dependency>

		<!-- 解密加密工具 -->
		<dependency>
			<groupId>org.bouncycastle</groupId>
			<artifactId>bcprov-jdk16</artifactId>
			<version>1.46</version>
		</dependency>

		<!-- 数据库连接池 -->
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>druid</artifactId>
			<version>1.1.9</version>
		</dependency>
		<dependency>
			<groupId>com.aliyun</groupId>
			<artifactId>aliyun-java-sdk-core</artifactId>
			<version>3.2.8</version>
		</dependency>
		<dependency>
			<groupId>com.aliyun.oss</groupId>
			<artifactId>aliyun-sdk-oss</artifactId>
			<version>2.8.3</version>
		</dependency>
		<dependency>
			<groupId>com.aliyun</groupId>
			<artifactId>aliyun-java-sdk-dysmsapi</artifactId>
			<version>1.1.0</version>
		</dependency>

		<!-- json工具 -->
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>fastjson</artifactId>
			<version>1.2.47</version>
		</dependency>
		<dependency>
			<groupId>com.aliyun</groupId>
			<artifactId>aliyun-java-sdk-cloudauth</artifactId>
			<version>1.1.2</version>
		</dependency>

		<!-- redis -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-redis</artifactId>
		</dependency>
		<!-- 手机三方验证 -->
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>fastjson</artifactId>
			<version>1.2.15</version>
		</dependency>
		<dependency>
			<groupId>org.apache.httpcomponents</groupId>
			<artifactId>httpclient</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.httpcomponents</groupId>
			<artifactId>httpcore</artifactId>
		</dependency>
		<!-- <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> 
			<version>2.6</version> </dependency> -->
		<dependency>
			<groupId>org.eclipse.jetty</groupId>
			<artifactId>jetty-util</artifactId>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<scope>test</scope>
		</dependency>

		<!--微信授权登录 -->
		<dependency>
			<groupId>commons-beanutils</groupId>
			<artifactId>commons-beanutils</artifactId>
			<version>1.8.3</version>
		</dependency>
		<dependency>
			<groupId>commons-codec</groupId>
			<artifactId>commons-codec</artifactId>
			<version>1.10</version>
		</dependency>
		<dependency>
			<groupId>commons-collections</groupId>
			<artifactId>commons-collections</artifactId>
			<version>3.2.1</version>
		</dependency>
		<dependency>
			<groupId>commons-httpclient</groupId>
			<artifactId>commons-httpclient</artifactId>
			<version>3.1</version>
		</dependency>
		<dependency>
			<groupId>commons-lang</groupId>
			<artifactId>commons-lang</artifactId>
			<version>2.6</version>
		</dependency>
		<dependency>
			<groupId>commons-logging</groupId>
			<artifactId>commons-logging</artifactId>
			<version>1.2</version>
		</dependency>
		<dependency>
			<groupId>net.sf.ezmorph</groupId>
			<artifactId>ezmorph</artifactId>
			<version>1.0.6</version>
		</dependency>
		<dependency>
			<groupId>org.apache.httpcomponents</groupId>
			<artifactId>httpclient</artifactId>
			<version>4.5.2</version>
		</dependency>
		<dependency>
			<groupId>org.apache.httpcomponents</groupId>
			<artifactId>httpcore</artifactId>
			<version>4.4.6</version>
		</dependency>
		<dependency>
			<groupId>net.sf.json-lib</groupId>
			<artifactId>json-lib</artifactId>
			<version>2.4</version>
			<classifier>jdk15</classifier>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-cache</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-redis</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
			<version>2.9.6</version>
		</dependency>
		<!-- <dependency> -->
		<!-- <groupId>com.alipay</groupId> -->
		<!-- <artifactId>alipay-sdk-java</artifactId> -->
		<!-- <version>3.0.0</version> -->
		<!-- <scope>system</scope> -->
		<!-- <systemPath>${project.basedir}/libs/alipay-sdk-java-3.0.0.jar</systemPath> -->
		<!-- </dependency> -->
		<dependency>
			<groupId>com.github.wxpay</groupId>
			<artifactId>wxpay-sdk</artifactId>
			<version>0.0.3</version>
		</dependency>
		
		<dependency>  
	        <groupId>com.google.zxing</groupId>  
	        <artifactId>javase</artifactId>  	
	        <version>3.0.0</version>  
    	</dependency>
		<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper -->
		<dependency>
		    <groupId>com.github.pagehelper</groupId>
		    <artifactId>pagehelper</artifactId>
		    <version>5.1.2</version>
		</dependency>
		
	</dependencies>

	<build>
		<!-- maven工具集成 -->
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<!-- <configuration> -->
				<!-- <includeSystemScope>true</includeSystemScope> -->
				<!-- </configuration> -->
			</plugin>
		</plugins>
	</build>

2.3属性配置文件application.properties

# DataSource
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource 
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#此配置是数据源,与数据库建立连接
spring.datasource.url=jdbc:mysql://47.98.199.254:3306/zhulimaoceshi?useUnicode=true&characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=docker

spring.datasource.tomcat.test-on-borrow=false  
spring.datasource.tomcat.test-while-idle=true  
spring.datasource.tomcat.time-between-eviction-runs-millis=3600000 

# Jpa validate
spring.jpa.hibernate.ddl-auto=none
spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl
spring.jpa.database=MYSQL
spring.jpa.show-sql=false 

# Logging
#logging.level.* = INFO
#logging.path=/usr/local/logApi

# upload
spring.servlet.multipart.max-file-size=100Mb
spring.servlet.multipart.max-request-size=1000Mb

## constant
AUDIT_TIME=10
SERVICE_PHONE = 400-007-7000
COUPON_NUM=2


spring.redis.host=47.98.199.254
spring.redis.port=7777
spring.redis.database=1
spring.redis.password=123456
spring.redis.jedis.pool.max-wait=1000
spring.redis.jedis.pool.max-active=100
spring.redis.jedis.pool.max-idle=50
spring.redis.jedis.pool.min-idle=10

2.4创建引导类

@SpringBootApplication
public class Application {
	public static void main(String[] args) {
		//启动springboot实例化spring容器调用内置的tomcat
		SpringApplication.run(Application.class, args);
	}
}

------------------------------------至此SpringBoot项目便搭建起来了--------------------------------------------
留言:剩余的部分只需要按照业务需求,将controller,server,dao层的调用关系建立起来便可以访问数据库了。

发布了21 篇原创文章 · 获赞 10 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_44167913/article/details/88380900