最近总是找springboot 的配置文件。不想每次创建新项目都找,所以记录一下。
springboot application.yml 配置文件。
server:
port: 8080
servlet:
context-path: /
spring:
application:
name: springboot
jpa:
show-sql: true
hibernate:
ddl-auto: update
properties:
hibernate.format_sql: true
open-in-view: false
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
datasource:
url: jdbc:mysql://127.0.0.1:3306/test1?autoReconnect=true
username: root
password: xxxxx
tomcat:
max-active: 4
min-idle: 2
initial-size: 2
hikari:
maximum-pool-size: 20
minimum-idle: 5
thymeleaf:
mode: HTML
encoding: UTF-8
servlet:
content-type: text/html
cache: false
mvc:
view:
prefix: classpath:/templates/
static-path-pattern: /**
resources:
static-locations: classpath:/static/
static-path-pattern: /**。 和 static-locations: classpath:/static/ 写好以后就可以在不用进入static页面访问里边的静态文件来。 而是直接写地址访问。 当然你可以自定义
@Configuration @EnableWebMvc public class WebConfig extends WebMvcConfigurerAdapter { }
还有一个最重要的pom.xml 看一下
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.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> <!-- 上边引入 parent,因此 下边无需指定版本 --> <!-- 包含 mvc,aop 等jar资源 --> <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> <!--spring操作数据库jpa 用于将数据存入数据库的类和方法的集--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <!-- 热部署 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> <scope>true</scope> </dependency> <!--spring模板引擎--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <!--数据库相关--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> <version>20180813</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
相关文章