2024-05-25|閱讀時間 ‧ 約 25 分鐘

[Java][Spring Boot]建立專案

建立Maven專案

  • 於pom.xml設定Spring Boot
<?xml version="1.0" encoding="UTF-8"?>
<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>xxx</groupId>
<artifactId>user</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
<!--引入Spring Boot核心Starter依賴-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<!--引入Spring Boot Maven-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>


  • 建立應用設定檔application.yml
spring:
application:
name: xxx
server:
port: xxx


  • 於pom.xml設定MyBatis
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.1</version>
</dependency>


  • 於pom.xml設定Druid
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.28</version>
</dependency>


  • 於pom.xml設定Mysql Connector
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>


  • 於用設定檔application.yml設定Mysql連線設定
datasource:
url: jdbc:mysql://xxx/user
username: root
password: 123456
type: xxx
driver-class-name: com.mysql.jdbc.Driver
separator: //


  • 於pom.xml設定Redis
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>


  • 於用設定檔application.yml設定Redis連接設定
redis:
host: 127.0.0.1
port: 6379
password: 123456
分享至
成為作者繼續創作的動力吧!
後端程式設計相關的內容,包含:PHP、Golang、Java、SQL...。
© 2024 vocus All rights reserved.