開始進入開發Spring Boot專案階段了,無論開發任何系統,就算在同一專案內,都會發現某些功能是需要重複共通使用,以之前的開發經驗,這裡整理分類並依Sprng Boot專案新增程式集中管理Package以及單元測試Package:




1.專案package位置(tw.lewishome.webapp.base.utility.common),按右鍵選擇 新增 => Class



參照新增Java程式,於專案位置為(src/test/java)的Unit測試Package,新增單元測試程式Aes256UtilsTest
(以後使用相同操作模式,新增其他程式方式,所以不再截圖說明了)
所有Java程式除基本的JDK提供元件功能函數以外,都會使用到第三方提供的原件(Dependency)以及專案開中的相關程式,後續介紹各類程式時,除了JDK以及 Spring Boot起始設定於Pom.xml(Dependency)以外,都會列出以下,專案相關程式以及第三方元件(Dependency)。
加入Pom.xml的結果,其他在需要加入第三方元件(Dependency),不再有截圖,請自行加入pom.xml

建議參考先將以下Pom.xml內容,調整新開發應用系統專案的Pom.xml內容,將包含了後續開發程式時需要的第三方元件(Dependency)。
*先註解Spring Security相關元件(Dependency),否則 Spring boot 的AutoConfig會啟動預設的Security,預計後續開發系統登入及安全相關設定時在開啟註解使用。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="https://maven.apache.org/POM/4.0.0"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- 源碼掃描 -->
<!-- https://hackmd.io/@ZYuC2002/SonarCube_Windows?utm_source=preview-mode&utm_medium=rec -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.7</version>
<relativePath />
<!-- lookup parent from repository -->
</parent>
<groupId>tw.lewishome</groupId>
<artifactId>webapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>webapp</name>
<description>WebApp project for Spring Boot</description>
<properties>
<!-- mvn versions:display-property-updates command to check the newest version available-->
<java.version>17</java.version>
<!-- project Encoding -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- project Encoding End -->
<!-- dependency version info -->
<AdminLTE-version>3.2.0</AdminLTE-version>
<commons-io.version>2.20.0</commons-io.version>
<oracle-jdbc.version>23.9.0.25.07</oracle-jdbc.version>
<H2-jdbc.version>2.4.240</H2-jdbc.version>
<jasperreports.version>7.0.3</jasperreports.version>
<jasypt.version>1.9.3</jasypt.version>
<poi-ooxml.version>5.4.1</poi-ooxml.version>
<zip4j.version>2.11.5</zip4j.version>
<json.version>20250517</json.version>
<jjwt.version>0.13.0</jjwt.version>
<passay.version>1.6.6</passay.version>
<bouncycastle.version>1.82</bouncycastle.version>
<maven-surefire.version>3.5.4</maven-surefire.version>
<openpdf.version>3.0.0</openpdf.version>
<jt400.version>21.0.5</jt400.version>
<logback.version>1.5.18</logback.version>
<springdoc.version>2.8.13</springdoc.version>
<postgresql-jdbc.version>42.7.3</postgresql-jdbc.version>
<owasp.esapi.version>2.7.0.0</owasp.esapi.version>
<jersey-test.version>4.0.0-M2</jersey-test.version>
<dompurify.version>3.2.7</dompurify.version>
<commons-pool2.version>2.12.1</commons-pool2.version>
<owasp.encoder.version>1.3.1</owasp.encoder.version>
<commons-logging.version>1.3.5</commons-logging.version>
<commons-text.version>1.14.0</commons-text.version>
<eclipse.jdt.version>3.43.0</eclipse.jdt.version>
<mazer.version>2.3.1</mazer.version>
<mybatis.version>3.0.5</mybatis.version>
<jasypt-maven.version>3.0.5</jasypt-maven.version>
<openliberty.tool.version>3.11.4</openliberty.tool.version>
<wlp.install.dir>//Users/lewis/wlp</wlp.install.dir>
<jpamodelgen.version>7.1.1.Final</jpamodelgen.version>
<!-- testing / coverage versions -->
<mockito.version>5.5.0</mockito.version>
<jacoco.version>0.8.10</jacoco.version>
<!-- dependency version info End -->
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework</groupId>
<artifactId>jersey-test-framework-core</artifactId>
<version>${jersey-test.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>AdminLTE</artifactId>
<version>${AdminLTE-version}</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>mazer</artifactId>
<version>${mazer.version}</version>
</dependency>
<dependency>
<groupId>org.webjars.npm</groupId>
<artifactId>dompurify</artifactId>
<version>${dompurify.version}</version>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency> -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>${commons-text.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId>
</dependency>
<!-- Spring boot JPA -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<!-- SQL Server (Microsoft) dependency -->
<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql-jdbc.version}</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<scope>provided</scope>
</dependency>
<!-- Oracle dependency -->
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc11</artifactId>
<version>${oracle-jdbc.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.sf.jt400</groupId>
<artifactId>jt400</artifactId>
<version>${jt400.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-processor</artifactId>
<version>${jpamodelgen.version}</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
</dependency>
<!-- Spring Boot JPA End-->
<!-- Spring Boot Security -->
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity6</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency> -->
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency> -->
<!-- End Spring Boot Security -->
<!-- Tools -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>${jjwt.version}</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>${jjwt.version}</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>${jjwt.version}</version>
</dependency>
<dependency>
<groupId>org.passay</groupId>
<artifactId>passay</artifactId>
<version>${passay.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>${json.version}</version>
</dependency>
<dependency>
<groupId>org.jasypt</groupId>
<artifactId>jasypt</artifactId>
<version>${jasypt.version}</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
<version>${bouncycastle.version}</version>
</dependency>
<!-- ZIP tools -->
<dependency>
<groupId>net.lingala.zip4j</groupId>
<artifactId>zip4j</artifactId>
<version>${zip4j.version}</version>
</dependency>
<!-- Excel access tools -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi-ooxml.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-full</artifactId>
<version>${poi-ooxml.version}</version>
</dependency>
<!-- Jasper Report -->
<!-- https://mvnrepository.com/artifact/net.sf.jasperreports/jasperreports -->
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>${jasperreports.version}</version>
<exclusions>
<exclusion>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/com.lowagie/itext -->
<!-- jasperreports 6.20.0 需要這個 itext -->
<!-- itext 有版權問題 改用 openpdf-->
<!-- https://mvnrepository.com/artifact/com.github.librepdf/openpdf -->
<dependency>
<groupId>com.github.librepdf</groupId>
<artifactId>openpdf</artifactId>
<version>${openpdf.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<!--devtools
end -->
<!-- auto configuration processor -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<!-- auto configuration processor end -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<!-- Found multiple occurrences of org.json.JSONObject -->
<exclusions>
<exclusion>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- GreenMail for mail testing -->
<dependency>
<groupId>com.icegreen</groupId>
<artifactId>greenmail</artifactId>
<version>2.0.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/nl.jqno.equalsverifier/equalsverifier-nodep -->
<!-- <dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier-nodep</artifactId>
<version>4.0</version>
<scope>test</scope>
</dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>jcache</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>${commons-logging.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>${eclipse.jdt.version}</version>
</dependency>
</dependencies>
<build>
<!-- war file name -->
<finalName>${project.artifactId}</finalName>
<!-- war file name -->
<!-- build package (include java src & local Lib) -->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
<include>**/lib/*.jar</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<!-- build package -->
<plugins>
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>${openliberty.tool.version}</version>
<configuration>
<installDirectory>${wlp.install.dir}</installDirectory>
<!-- <runtimeArtifact>
<groupId>com.ibm.websphere.appserver.runtime</groupId>
<artifactId>wlp-kernel</artifactId>
<version>${wlp-kernel.version}</version>
<type>zip</type>
</runtimeArtifact> -->
<serverName>localhost</serverName>
<debug>true</debug> <!-- Optional: if you want the plugin to start in debug mode -->
<debugPort>7777</debugPort> <!-- Optional: specify a custom debug port -->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<id>deploy-artifacts</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Add maven-surefire-plugin for skip test when build -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
<dependenciesToScan>
<dependency>org.junit.jupiter</dependency>
</dependenciesToScan>
</configuration>
</plugin>
<!-- skip test end -->
<!-- Auto generate Maven javadoc -->
<!-- <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<charset>UTF-8</charset>
<encoding>UTF-8</encoding>
<docencoding>UTF-8</docencoding>
</configuration>
<executions>
<execution>
<id>maven-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin> -->
<!-- Maven javadoc End-->
<plugin>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-maven-plugin</artifactId>
<version>${jasypt-maven.version}</version>
</plugin>
<!-- https://hackmd.io/@ohQEG7SsQoeXVwVP2-v06A/SyqKpzwvJx -->
<!-- 測試覆蓋率報告 -->
<!-- mvn clean verify 後,會在 target > jacoco-report 資料夾下生成測試覆蓋率報告 index.html -->
<!-- 確保使用最新版 -->
<!-- <plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin> -->
</plugins>
</build>
<!-- <repositories>
<repository>
<id>maven-releases</id>
<name>maven-releases</name>
<url>https://nexus.lewishome.tw/repository/maven-releases</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>maven-releases</id>
<name>maven-releases</name>
<url>https://nexus.lewishome.tw/repository/maven-releases</url>
</repository>
<snapshotRepository>
<id>maven-snapshots</id>
<name>maven-snapshots</name>
<url>https://nexus.lewishome.tw/repository/maven-snapshots</url>
</snapshotRepository>
</distributionManagement> -->
</project>