Maven+SpringBoot环境搭建

来源:互联网 发布:php数组添加键值对 编辑:程序博客网 时间:2024/05/22 02:30

1.首先创建一个maven项目
maven项目

2.maven项目创建完毕之后,其项目结构如下:
这里写图片描述

3.打开pom文件,并添加相关依赖:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  <modelVersion>4.0.0</modelVersion>  <groupId>mangentSystem</groupId>  <artifactId>mangetsystem</artifactId>  <version>0.0.1-SNAPSHOT</version>  <name>mangetsystem</name>  <description>管理平台</description>  <!-- 继承父包 -->    <parent>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-parent</artifactId>        <version>1.5.7.RELEASE</version>    </parent>    <!-- spring-boot的web启动的jar包 -->    <dependencies>        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-web</artifactId>        </dependency>     </dependencies>       <!--maven的插件-->    <build>        <plugins>            <plugin>                <groupId>org.springframework.boot</groupId>                <artifactId>spring-boot-maven-plugin</artifactId>            </plugin>        </plugins>    <!-- 配置java版本 不配置的话默认父类配置的是1.6-->    <pluginManagement>      <plugins>        <plugin>          <artifactId>maven-compiler-plugin</artifactId>          <configuration>            <source>1.8</source>            <target>1.8</target>          </configuration>        </plugin>      </plugins>    </pluginManagement>  </build></project>

4.创建主类Application.java

package com.core;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.Configuration;@Configuration@EnableAutoConfiguration//basePackages 声明扫描路径@ComponentScan(basePackages="com.boot.web")public class Application {    public static void main(String[] args) {        SpringApplication.run(Application.class, args);    }}5.创建属性文件application.proterties

spring.datasource.platform=mysql
spring.datasource.url=jdbc:mysql://localhost/springboot?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&autoReconnect=true&failOverReadOnly=false
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driverClassName=com.mysql.jdbc.Driver

Advanced configuration…

spring.datasource.max-active=50
spring.datasource.max-idle=6
spring.datasource.min-idle=2
spring.datasource.initial-size=6

create table

spring.jpa.hibernate.ddl-auto=validate

//声明tomcat的端口号
server.port=8888
server.session-timeout=30
server.tomcat.uri-encoding=UTF-8

spring.thymeleaf.prefix=classpath:templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false

5.在浏览器中输入localhost:8888/,调试结果如下:

这里写图片描述

原创粉丝点击