我怎样才能快速运行我的项目?

时间:2016-12-29 06:46:32

标签: spring hibernate spring-data-jpa

这是我的database.properties文件,用于存储数据库
    信息

 ################### JDBC Configuration ##########################
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/eduman_em?
verifyServerCertificate=false&useSSL=false&requireSSL=false
jdbc.username=root
jdbc.password=1234

 ########## Hibernate Configuration #########
  hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
  #### hibernate.show_sql=true
  #### hibernate.hbm2ddl.auto=update
  #### hibernate.generate_statistics=true
  hibernate.connection.charSet=UTF-8
  hibernate.ejb.naming_
  strategy=org.hibernate.cfg.ImprovedNamingStrategy
  hibernate.cache.provider_class=
  org.hibernate.cache.HashtableCacheProvider
  ################## For List insertion Hiber Config    
  ###hibernate.order_inserts=true###
  ####hibernate.order_updates=true####

This is my **applicationContext-db.xml**



<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.2.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd">


<!-- Scan for property files -->
<context:property-placeholder location="classpath:META-INF/spring/*.properties"/>

    <!-- Transaction Manager -->
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
        <property name="dataSource" ref="dataSource" />
    </bean>
    <!-- Detect @Transactional -->
    <tx:annotation-driven transaction-manager="transactionManager" />


    <!-- Entity Manager Factory -->
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="jpaVendorAdapter">
        <!-- Define Hibernate JPA Vendor Adapter -->
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
           <!-- <property name="generateDdl" value="true" /> -->
            <property name="database" value="MYSQL" />
        </bean>
        </property>
        <!-- Persistence Unit -->
        <property name="persistenceUnitName" value="persistenceUnit"/>
    </bean>

<bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource"
        p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}"
        p:username="${jdbc.username}" p:password="${jdbc.password}" />


    <bean
        class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
        <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource" ref="dataSource" />
</bean>

</beans>

我使用的是mysql数据库。我的数据库大小为552 MB。当我运行我的项目时,它需要超过5分钟。如果我使用100 MB以下/小数据库,那么它运行速度很快。我该如何先运行我的项目。 感谢。

1 个答案:

答案 0 :(得分:0)

@ Nasir

你可以去Hikari Connection Pool.Return Hikari DataSource对象。示例代码如下:

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;


@Bean
public DataSource dataSource() {
    // In classpath from spring-boot-starter-web
    final Properties props = new Properties();
    props.put("driverClassName", "com.mysql.jdbc.Driver");
    props.put("jdbcUrl", "jdbc:mysql://localhost:3306/master?createDatabaseIfNotExist=false");
    props.put("username", "root");
    props.put("password", "mysql");
    HikariConfig hc = new HikariConfig(props);
    HikariDataSource ds = new HikariDataSource(hc);
    return ds;
}