Play Frameworkシリーズの1つがプレイフレームワークのspringシステムを構築する方法


1概要
4年前、spring mvcフレームワークからplay frameworkフレームワークに移行したのは完全により速く、より良い起業のためで、その時spring mvc配置の肥大化とtomcat研究開発時のロードに耐えられず、php開発に転向しようとしたが、javaへの愛を捨てるのは難しい.何気なくplay frameworkを発見し、目の前を明るくした.すぐに1、2日かけて深く研究したところ、それは私の理想的なjavaフレームワークであり、私の柔軟な構成を満たすと同時にtomcatを捨てることができ、マルチプラットフォームとtomcatに配置することができます.ずっとこのように堅持して4年使って、ずっと1.2を使っています.xバージョンも、このバージョンが一番安定していると思います.2.0以上のバージョンはjavaスタイルではありません.
 
2フレーム構築
私はMVCアーキテクチャを3つのシステムに分けて設計するのが好きで、M私はデータシステムで代替することができて、V私は業務システムで代替することができて、C私は私のインタフェースシステムが代替するのが好きで、このように開発するのは仕事量を増大することができますが、実は熟練している人にとって、この仕事量は無視することができます.しかし、これは将来のプラットフォームの拡張とビジネスの明確さと理解、開発の純粋さと品質に大きなメリットがあります.
    
3データシステム構成
まずplayフレームワークプロジェクトを構築し、mybatisとspringを組み合わせてspring 1を手動でロードします.0.3は地元のmoduelsにあります.
dependenciesでymlファイルでの構成
- play
    - org.mybatis -> mybatis 3.1.1
    - org.mybatis -> mybatis-spring 1.1.1
    - com.jolbox -> bonecp 0.7.1.RELEASE
    - play -> spring 1.0.3

 
    
アプリケーションでconfファイルの末尾にspring構成をロード
     
# The spring module
    module.spring=${play.path}/modules/spring-1.0.3
    play.spring.component-scan=true
    play.spring.component-scan.base-packages=models
    play.spring.add-play-properties=false

 
データベース接続の設定
   
public class BoneCPDataSourceFactoryBean implements FactoryBean<BoneCPDataSource>, InitializingBean{
	
	private BoneCPDataSource boneCPDataSource;
	
	public final static int DEFAULT_POOL_MAX_SIZE = 30;
	
	public final static int DEFAULT_POOL_MIN_SIZE = 10;
	
	

	@Override
	public BoneCPDataSource getObject() throws Exception {
		return boneCPDataSource;
	}

	@Override
	public Class<?> getObjectType() {
		return BoneCPDataSource.class;
	}

	@Override
	public boolean isSingleton() {
		return true;
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		boneCPDataSource = new BoneCPDataSource();
		boneCPDataSource.setJdbcUrl(Play.configuration.getProperty("db.url"));
		boneCPDataSource.setUsername(Play.configuration.getProperty("db.user"));
		boneCPDataSource.setPassword(Play.configuration.getProperty("db.pass"));
		boneCPDataSource.setDriverClass(Play.configuration.getProperty("db.driver"));
		boneCPDataSource.setMaxConnectionsPerPartition(getIntValue("db.pool.maxSize", DEFAULT_POOL_MAX_SIZE));
		boneCPDataSource.setMinConnectionsPerPartition(getIntValue("db.pool.minSize", DEFAULT_POOL_MIN_SIZE));
	}
	
	public int getIntValue(String config, int defalutValue){
		String value = Play.configuration.getProperty(config );
		if(!StringUtils.isEmpty(value)){
			try{
				defalutValue = Integer.parseInt(value);
			}catch (Exception e) {
			}
		}
		return defalutValue;
	}

}

 
 
内部データシステムと業務システムとの間の通信はrmiを採用するのでアプリケーション.conf構成
     
#rmi        。
    bsd.rmi.server.host=localhost
    bsd.rmi.server.port=1100

 
 
rmiサービスクラスの作成
public class BsdRmiServiceExporter extends RmiServiceExporter {

	@Override
	public void afterPropertiesSet() throws RemoteException {
		System.setProperty("java.rmi.server.hostname ", Play.configuration.getProperty("bsd.rmi.server.host"));
		super.afterPropertiesSet();
	}
}

 
アプリケーション-contextを作成します.xmlファイル構成rmiとmybatis
    
<bean
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<value>classpath:application.conf</value>
		</property>
	</bean>

	<bean id="dataSource" class="common.jdbc.datasource.BoneCPDataSourceFactoryBean" />

	<tx:annotation-driven transaction-manager="transactionManager"
		proxy-target-class="true" />

	<!-- Transaction manager for a single JDBC DataSource -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>

	<!-- SqlSessionFactory -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="configLocation" value="classpath:mybatis/configuration.xml"></property>
		<property name="mapperLocations" value="classpath:models/model/mapper/*.xml" />
	</bean>

	<bean id="bsdRmiServiceExporter" class="common.rmi.BsdRmiServiceExporter">
		<property name="serviceName" value="bsdRmiService" />
		<property name="service" ref="bsdRmiService" />
		<property name="serviceInterface" value="models.rmi.BsdRmiService" />
		<property name="registryPort" value="${bsd.rmi.server.port}" />
	</bean>

 
4業務システム構成
ビジネスファクトリクラスの作成
    
public class RmiService {
	
	public static BsdRmiService getBsdRmiService()
	{
		return (BsdRmiService)play.modules.spring.Spring.getBean("bsdRmiService");
	}
}

 
アプリケーションでconfにrmi受信ポートを構成する
     rmi.base.url=rmi://localhost:1100
 
rmiファイルアプリケーション-contextを構成します.xm
   
<bean
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<value>classpath:application.conf</value>
		</property>
	</bean>
	
	<bean id="bsdRmiService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
		<property name="serviceUrl" value="${.rmi.base.url}/bsdRmiService" />
		<property name="serviceInterface" value="models.rmi.BsdRmiService" />
		<property name="lookupStubOnStartup" value="false" />
		<property name="refreshStubOnConnectFailure" value="true" />
	</bean>

 
5インタフェースシステム構成
Play frameworkはインタフェースが非常によくできるフレームワークで、特にrestfulやhttpなどは、renderJSONだけでhttpインタフェースを公開することができます.
GETまたはPOSTインタフェースをパブリッシュするには、routesファイルで構成するだけでいいので、ここでは詳しく説明しません.
 
後で私は時間を割いていくつかの仕事の段階で出会った問題と解決方法を書くことができて、これらを書くのも何年もの仕事の経験を記録して、ノートにそれを残します.