且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在不更改 main(args[]) 方法的情况下将 spring boot 添加到现有项目

更新时间:2021-06-28 01:31:09

将此添加到您的 pom.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.2.RELEASE</version>
</parent>

POM:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.2.RELEASE</version>
    </parent>

    <dependencies>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>

那就是你需要给spring boot一个connector,还有一个application.properties数据库的连接信息.例如:

That is you need to give spring boot a connector and also a application.properties on connection information of the database. For example:

# database
spring.datasource.url= jdbc:mysql://****
spring.datasource.username=****
spring.datasource.password=****

#ddl generation
spring.jpa.hibernate.ddl-auto=update

# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.testWhileIdle = true
spring.datasource.testOnBorrow=true
spring.datasource.timeBetweenEvictionRunsMillis = 3600000
spring.datasource.validationQuery = SELECT 1

# Number of ms to wait before throwing an exception if no connection is available.
spring.datasource.max-wait=10000

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

# Show or not log for each sql query
spring.jpa.show-sql = true

# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy

# Use spring.jpa.properties.* for Hibernate native properties (the prefix is
# stripped before adding them to the entity manager)

# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect