Intellij idea + Spring boot + Thymeleaf + MySQL

时间:2025-04-10 07:38:12

1.版本

idea 2016.2.4 +;
boot 1.3.8;
5.6 +;

配置

<!--  use a later Java version -->
<properties>
    <>1.8</> <!--  use a later Java version -->
</properties>

<!-- Inherit defaults from Spring Boot -->
<parent>
    <groupId></groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.</version>
</parent>

<!-- Add typical dependencies for a web application -->
<dependencies>
<dependency>
    <groupId></groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
    <exclusions>
        <exclusion>
            <groupId></groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId></groupId>
    <artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
<dependency>
    <groupId></groupId>
    <artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
    <groupId></groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
    <groupId></groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId></groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>

<!-- Developer tools -->
<dependency>
    <groupId></groupId>
    <artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies>
<repositories>
    <repository>
        <id>spring-milestone</id>
        <url>/libs-release</url>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>spring-milestone</id>
        <url>/libs-release</url>
    </pluginRepository>
</pluginRepositories>

启动类

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application {

    private final Logger log = LoggerFactory.getLogger(Application.class);

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

配置

-request-size=100MB
-file-size=100MB

=@@
=@@
# LOGGING
=
=logs

=logs
=true
=true
=true
=jdbc:mysql://localhost/isy?useUnicode=true&characterEncoding=utf-8&useSSL=false
=root
=123456
-class-name=
=isy
# Number of ms to wait before throwing an exception if no connection is available.
-wait=10000

# Maximum number of active connections that can be allocated from this pool at the same time.
-active=50

-idle=50

# Validate the connection before borrowing it from the pool.
-on-borrow=true

-query=select 1;
 = 8443
-path=
=true
=/**

5.说明

1.一般 是在你建的包最顶层,如我的在 下方,其余包都在下,如 ,等等,
这样启动时才能扫描到注解等等。
据官方文档解释有三种方式,其中一种是扫描根目录,因此放在resources目录下即可。
idea热加载方式是需要ctrl+F9来重新编译下才可,但有时还是会有问题,比如重新加载后丢失spring 创建的对象而报错,一般不改或增加注解没什么问题。
4.这里没有使用tomcat 而是 undertow,官方默认是tomcat,我这里是按照生产环境配置的,当然也可以配置成application-*.properties使用profile
来切换环境,这里的示例是简单配置。
5.启动类里我没有使用@SpringBootAutoConfiger,这样便于后期加缓存,spring security等,你也可以使用该方式简化配置。
6.在生产环境里应该将配置文件中的devtools设置为false。

到 github: ISY 查看更多高级配置。