2016-12-29 79 views
0

這裏是一個用於存儲數據庫
信息如何快速運行我的項目?

################### 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數據庫我database.properties文件。我的數據庫大小爲552 MB。當我運行我的項目需要5分鐘以上。如果我使用100 MB以下/小型數據庫,那麼它運行得很快。我怎樣才能運行我的項目。 謝謝。

+1

這是認真你的問題?你提供你的數據庫配置,陳述它的大小,並抱怨'項目'速度緩慢,你是否用PrimeFaces標記這個問題?而你的標題'只'表示'春天hibernate jpa',其中只有'hibernate'似乎直接相關。既然你已經有19個聲望點,我100%肯定你可以做得更好,我正在重申你的問題 – Kukeltje

+0

先生,我添加了數據庫配置文件和數據庫大小 –

回答

0

@納西爾

你可以去下面阿光連接Pool.Return阿光數據源object.Sample代碼:

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; 
} 
+0

先生,我不能使用這個類,因爲當我導出war文件那麼我不能更改數據庫網址,用戶名和密碼。我需要在導出war文件後更改數據庫網址,用戶名和密碼。 –

+0

我不是說要改變你的數據庫細節....我想說的是在你的數據源上使用Hikari連接池... HikariConfig hc = new HikariConfig(props); HikariDataSource ds = new HikariDataSource(hc); –

+0

先生,我也可以使用HikariDataSource,但問題沒有解決。 –