Springboot檔案結構和配置檔案
阿新 • • 發佈:2018-12-17
1.檔案結構
| -demo1-------------------------------------專案名稱 | | -.idea | | | -libraries | | | | -compiler.xml | | | | -encodings.xml | | | | -misc.xml | | | | -modules.xml | | | | -workspace.xml | | -.mvn | | | -wrapper | | | | -maven-wrapper.jar | | | | -maven-wrapper.properties | | -src-----------------------------------原始碼檔案目錄 | | | -main | | | | -java-----------------------------目錄下放置所有java檔案的原始碼檔案 | | | | | -com.example.demo | | | | | | -DemoApplication------------主函式入口類 | | | | -resources------------------------放置所有的配置檔案,頁面檔案,靜態資原始檔 | | | | | -static | | | | | -templates | | | | | -application.properties--------配置檔案 | | | -test--------------------------------測試功能檔案目錄 | | | | -java | | | | | com.example.demo | | | | | | DemoApplicationTests---------測試類 | -.gitignore | -demo1.iml | -mvnw | -mvnw.cmd | -pom.xml----------------------------------Maven管理:原始碼、配置檔案、開發者的資訊和角色、問題追蹤系統、組織資訊、專案授權、專案的url、專案的依賴關係等等 | -External Libraries | -Scartches and Consoles
2.配置檔案
常用的配置檔案主要有兩個:
application.properties:各種配置,比如執行埠等,專案初始化後此檔案是空的,需要自己新增配置,不配置預設8080.
pom.xml:Maven對各種包資源的管理
常見的application.properties
# 服務埠號 server.port=8088 # 應用名稱,一般就是專案名稱,這個名稱在SpringCloud中比較關鍵 spring.application.name=customer #指定當前的活動配置檔案,主要用於多環境多配置檔案的應用中 spring.profiles.active=dev #配置在使用Thymeleaf做頁面模板時的字首,即頁面所在路徑 spring.thymeleaf.prefix=classpath:/templates/ #設定在使用Thymeleaf做頁面模板時的字尾 spring.thymeleaf.suffix=.html #設定在使用Thymeleaf做頁面模板時是否啟用快取 spring.thymeleaf.cache=false #設定靜態資源的請求路徑 spring.mvc.static-path-pattern=/** #指定靜態資源的路徑 spring.resources.static-locations=classpath:/static/,classpath:/public/ server.servlet.context-path=/adapter management.endpoints.web.exposure.include=* management.endpoints.web.exposure.exclude=env,beans spring.datasource.name=test spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=gbk&zeroDateTimeBehavior=convertToNull spring.datasource.username=root spring.datasource.password=123456 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.filters=stat spring.datasource.maxActive=20 spring.datasource.initialSize=1 spring.datasource.maxWait=60000 spring.datasource.minIdle=1 spring.datasource.timeBetweenEvictionRunsMillis=60000 spring.datasource.minEvictableIdleTimeMillis=300000 spring.datasource.validationQuery=select 'x' spring.datasource.testWhileIdle=true spring.datasource.testOnBorrow=false spring.datasource.testOnReturn=false spring.datasource.poolPreparedStatements=true spring.datasource.maxPoolPreparedStatementPerConnectionSize=20 spring.datasource.maxOpenPreparedStatements=20 mybatis.mapper-locations=classpath:mapping/*.xml mybatis.type-aliases-package=com.example.bootdemo.model mapper.mappers= com.example.bootdemo.dao mapper.not-empty=false mapper.identity=MYSQL #pagehelper分頁外掛 pagehelper.helperDialect=mysql pagehelper.reasonable=true pagehelper.rowBoundsWithCount=true pagehelper.supportMethodsArguments=true pagehelper.offsetAsPageNum=true pagehelper.returnPageInfo=check #pagehelper.params=count=countSql # Redis資料庫索引(預設為0) spring.redis.database=0 # Redis伺服器地址 spring.redis.host=127.0.0.1 # Redis伺服器連線埠 spring.redis.port=6379 # Redis伺服器連線密碼(預設為空) spring.redis.password=123456 # 連線池最大連線數(使用負值表示沒有限制) spring.redis.jedis.pool.max-active=8 # 連線池最大阻塞等待時間(使用負值表示沒有限制) spring.redis.jedis.pool.max-wait=-1 # 連線池中的最大空閒連線 spring.redis.jedis.pool.max-idle=8 # 連線池中的最小空閒連線 spring.redis.jedis.pool.min-idle=0 # 連線超時時間(毫秒) spring.redis.timeout=5000
pom.xml檔案:常用的就是新增dependency節點,新增依賴項,maven會自動提示是否載入資原始檔
<?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>com.example</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>demo</name> <description>Demo project for Spring Boot</description> <!-- 父專案的座標。如果專案中沒有規定某個元素的值,那麼父專案中的對應值即為專案的預設值。 座標包括group ID,artifact ID和 version。 --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.6.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <!-- 專案開發者屬性,如即時訊息如何處理等 --> <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> <!-- webservices --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web-services</artifactId> </dependency> <!-- log4j12日誌 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </dependency> <!-- springboot監控 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!-- jdbc --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <!-- mybatis支援 --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.2</version> </dependency> <!-- mysql驅動 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <!-- tomcat支援 --> <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-test</artifactId> <scope>test</scope> </dependency> <!-- 新增redis支援--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <!-- spring 使用redis 儲存session狀態. --> <!-- <dependency> <groupId>org.springframework.session</groupId> <artifactId>spring-session-data-redis</artifactId> </dependency> --> <!-- <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-pool2</artifactId> <version>2.4.2</version> </dependency> --> <!-- <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> </dependency> <dependency> <groupId>com.fasterxml.jackson.datatype</groupId> <artifactId>jackson-datatype-joda</artifactId> </dependency> <dependency> <groupId>com.fasterxml.jackson.module</groupId> <artifactId>jackson-module-parameter-names</artifactId> </dependency> --> <!-- 分頁外掛 --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.1.3</version> </dependency> <!-- alibaba的druid資料庫連線池 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.0</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.0</version> </dependency> <!-- 工具類 --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> </dependency> <!-- 熱部署 --> <!-- 這個需要為 true 熱部署才有效 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency> <!-- 自定義配置 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency> <!-- jsp支援 --> <!-- <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-spring</artifactId> <version>1.2.2</version> </dependency> --> <!-- 驗證碼 --> <!-- <dependency> <groupId>com.github.penggle</groupId> <artifactId>kaptcha</artifactId> <version>2.3.2</version> </dependency> --> <!-- 阿里json --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.47</version> </dependency> <dependency> <groupId>com.tencentcloudapi</groupId> <!-- 注:這裡的版本號請參考github或者maven倉庫最新版本號 --> <artifactId>tencentcloud-sdk-java</artifactId> <version>3.0.8</version> </dependency> <dependency> <groupId>dom4j</groupId> <artifactId>dom4j</artifactId> </dependency> </dependencies> <!-- 構建專案需要的資訊 --> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>