2017-02-28 5 views
1

私はspring、jpa、hibernateとdatabase mysqlとserver Apache Tomcat 8を開発しているWebプロジェクトを持っています。私のプロジェクトのサイズは87 MBです。データベースのサイズは1 GBです。プロジェクトを実行すると、展開に20分以上かかります。ひかり接続プールも適用しますが、問題は解決しません。 I設定ファイルなどの関連ファイルを提供します。Spring Jpa Hibernateプロジェクトの展開時間を短縮するにはどうしたらいいですか?

これは私のdatabase.propertiesは、これは私のエンティティマネージャクラスですこれは私の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> 

ある

################### JDBC Configuration ########################## 
jdbc.driverClassName=com.mysql.jdbc.Driver 

jdbc.url=jdbc:mysql://localhost:3306 
/emdemo_liza?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#### 

ファイルです

package com.netizenbd.dao.service; 

import java.lang.reflect.ParameterizedType; 
import java.lang.reflect.Type; 
import java.util.List; 

import javax.persistence.EntityManager; 
import javax.persistence.EntityManagerFactory; 
import javax.persistence.PersistenceContext; 
import javax.persistence.Query; 

import org.hibernate.HibernateException; 
import org.springframework.transaction.annotation.Transactional; 

import com.netizenbd.dao.EntityDao; 

import javassist.bytecode.SignatureAttribute.TypeVariable; 

public class EntityService<E> implements EntityDao<E> { 

    @PersistenceContext(unitName="persistenceUnit") 
    protected EntityManager entityManager; 

    protected E instance; 
    private Class<E> entityClass; 

    @Transactional 
    public void persist(E e) throws HibernateException{  
     getEntityManager().persist(e); 
     getEntityManager(); 

    } 
    @Transactional 
    public void merge(E e) throws HibernateException{  
     getEntityManager().merge(e); 
    } 
    @Transactional 
    public void remove(Object id) throws Exception{  
     getEntityManager().remove((E)getEntityManager().find(getEntityClass(), id)); 

    } 

    @Transactional(readOnly = true) 
    public E findById(Object id) throws Exception {  
     return (E)getEntityManager().find(getEntityClass(), id);  
    } 

    @Transactional(readOnly = true) 
    public E findAcademicYearObj(Object id, Object year) throws Exception {  
     return (E)getEntityManager().find(getEntityClass(), id +"and"+ year);  
    } 

    @Transactional(readOnly = true) 
    @SuppressWarnings("unchecked") 
    public List<E> findAll() throws Exception{ 
     return getEntityManager().createQuery("Select t from " + getEntityClass().getSimpleName() + " t").getResultList(); 
    } 
} 

Tomcatサーバーを使用して短時間でプロジェクトを展開する方法を教えてください。

おかげ

+2

私は、フレームワークレベルの文章のログファイルを分析することをお勧めします。最大のチャンクが消費される場所を確認し、休止状態にします。 (* INFOログが不足している場合には 'DEBUG'レベルのログを有効にする*)これは潜在的な原因を絞り込むのに役立ちます。 –

+0

'hibernate.hbm2ddl.auto'を' none'に設定すると、あなたのスキーマの作成を休止します(変更を検出する必要があるため、特に 'update'で長時間かかる)。また、 'generetaDdl'プロパティを' false'に設定する必要があります。また、適切な接続プールを使用することもできます( 'DriverManagerDataSource'は、状況のように本番環境で使用するためのものではありません)。コンポーネントスキャンを使用している場合は、スキャンする必要があるパッケージの量を制限します。 –

答えて

0

は簡単に言えば、次のプロパティを使用しないでください。

hibernate.hbm2ddl.auto=update 

あなたはこのようなフライウェイやLiquiBaseをとしてデプロイ時に本番環境のスキーマを移行するために他のツールを使用してではなく、する必要がありますHibernateスキーマツール。

このプロパティを次のように設定すると、起動時間が大幅に短縮されます。

hibernate.hbm2ddl.auto=none 
+0

hibernate.hbm2ddl.auto = updateを削除してhibernate.hbm2ddl.auto = noneを追加できますが、問題は解決しません –

+0

次に、遅い場所とアプリケーションが何をしているかについての詳細を提供する必要があります。 – Naros

関連する問題