2009-09-07
Spring+HibernateEntityManager(archetype編)
前回のおさらい
前回は、component-scan を用いつつ、ドメインモデル実装中の SpringFramework に依存したアノテーションを排除しました。
今回のテーマ
今回は、Spring+HibernateEntityManager 環境のサンプルプロジェクトの生成を、maven の maven-archetype-plugin を用いて行います。
サンプルの内容について
基本的に、前回 までの内容に沿った内容になっています。
前回から1年3ヶ月も経っているので、微妙に軌道修正しているところはありますが (^^;
archetypeからのmavenプロジェクト作成方法
settings.xmlの設定
以下の内容を追加します。
<?xml version="1.0" encoding="UTF-8"?> <!-- References: - http://maven.apache.org/maven-settings/settings.html - http://maven.apache.org/settings.html --> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <profiles> <profile> <id>objectfanatics</id> <activation> <activeByDefault>true</activeByDefault> </activation> <repositories> <repository> <id>objectfanatics</id> <url>http://domaingen.sourceforge.jp/maven2</url> <layout>default</layout> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>objectfanatics</id> <url>http://domaingen.sourceforge.jp/maven2</url> <layout>default</layout> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> </settings>
プロジェクト生成
archetypeを指定して、プロジェクトを生成します。
mvn org.apache.maven.plugins:maven-archetype-plugin:2.0-alpha-4:generate -DarchetypeGroupId=jp.objectfanatics.archetype.ddd -DarchetypeArtifactId=ddd-archetype -DarchetypeVersion=0.0.2 -DarchetypeRepository=http://domaingen.sourceforge.jp/maven2/
いくつか質問されるので、自分の好みの情報を入力します。
Define value for groupId: : com.example Define value for artifactId: : test-artifact Define value for version: 1.0-SNAPSHOT: : 0.0.1-SNAPSHOT Define value for package: com.example: : Confirm properties configuration: groupId: com.example artifactId: test-artifact version: 0.0.1-SNAPSHOT package: com.example Y: :
DB環境設定
DBに関する環境設定は、以下の2箇所で行っていますので、必要に応じて変更してください。
domain層のテスト用
domain/domain-impl/src/test/resources/beans.xml
application層用
application/src/main/resources/beans.xml
両方とも、デフォルトのDB設定は以下のようになっています。そのため MySQL5.0 系をデフォルトでインストールしてそのまま起動すれば、DB環境設定は完了です。
<!-- raw datasource --> <bean id="rawDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/test" /> <property name="username" value="root" /> <property name="password" value="" /> <property name="validationQuery" value="SELECT 1" /> </bean>
テストの実行
DBアクセスを含むいくつかのテストがサンプルに含まれていますので、以下のようにしてテストを実行し、環境が正しく構築されているか確認します。
mvn clean test
links
第1回 Spring+HibernateEntityManager(HibernateEntityManager単体編)
第2回 Spring+HibernateEntityManager(とりあえずSpring編)
第3回 Spring+HibernateEntityManager(宣言的トランザクション編)
第4回 Spring+HibernateEntityManager(Spring+DDDっぽく編)
第5回 Spring+HibernateEntityManager(Spring+DDDっぽく編 その2)
第6回 Spring+HibernateEntityManager(Spring+DDDっぽく編 その3)
第7回 Spring+HibernateEntityManager(Spring+DDDっぽく編 その4)
第8回 Spring+HibernateEntityManager(@Transactionalアノテーション編)
第9回 Spring+HibernateEntityManager(@Required編)
第10回 Spring+HibernateEntityManager(XMLからの外部リソース参照編)
第11回 Spring+HibernateEntityManager(AspectJ AOP with Load-Time-Weaver編)
第12回 Spring+HibernateEntityManager(DBCPのvalidationQuery編)
第13回 Spring+HibernateEntityManager(@Resource編)
第14回 Spring+HibernateEntityManager(コンポーネント自動検出 with アノテーション編)
第15回 Spring+HibernateEntityManager(コンポーネント自動検出 without アノテーション編)
第16回 Spring+HibernateEntityManager(archetype編)
- 362 http://pipes.yahoo.com/pipes/pipe.info?_id=45d5a8c4e92dd6d0ea2937e5cbb455bf
- 48 http://www.google.co.jp/search?hl=ja&client=firefox-a&rls=org.mozilla:ja:official&hs=MiS&q=eclipse+javadoc+UTF-8&btnG=検索&lr=lang_ja
- 39 http://www.google.co.jp/search?sourceid=navclient&hl=ja&ie=UTF-8&rlz=1T4ADBR_jaJP263JP264&q=SVNキーワード
- 24 http://www.google.co.jp/search?hl=ja&lr=lang_ja&client=firefox-a&rls=org.mozilla:ja:official&q=log4j+rootLogger+logger&start=10&sa=N
- 14 http://www.google.co.jp/search?hl=ja&source=hp&q=eclipse+javadoc&lr=&aq=1&oq=eclipse+j
- 12 http://www.google.com/search?hl=ja&lr=lang_ja&ie=UTF-8&oe=UTF-8&q=xml+ヘッダ&num=50
- 10 http://www.google.co.jp/search?client=firefox-a&rls=org.mozilla:ja:official&channel=s&hl=ja&source=hp&q=Sun BugParade&lr=&btnG=Google+検索
- 9 http://www.google.co.jp/search?hl=ja&client=firefox-a&channel=s&rls=org.mozilla:ja:official&hs=xuk&q=Transactional&btnG=検索&lr=
- 9 http://www.google.co.jp/search?q=transactional&lr=lang_ja&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:ja:official&client=firefox-a
- 8 http://www.google.co.jp/search?q=@Transactional&lr=lang_ja&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:ja:official&client=firefox-a




