Quellcode durchsuchen

Place classpath-root files under resources/ directory, which is the prefered location.

Split context files per layer, allowing easy testing of a subset of the layers.

Split Jdbc and Hibernate configuration in separate test and production files, where that makes sense, and keep common properties in a single location (context file). Properties files are pulled into the context by Spring.  

Split out a javax.sql.DataSource bean, which is handy for a number of reasons.

Hibernate configuration prepared, but no classes are mapped. Test config is in-memory and verbose, production is file-based and quieter.

Transaction is annotation-driven in the service layer.

Jetty Maven plugin added, and added context loading listener to web.xml. It's now possible to run "mvn jetty:run" and find the tracking page on localhost:8080/dddsample.

Added dev.java.net maven repository with JTA artifact available.
peter_backlund vor 19 Jahren
Ursprung
Commit
659783bd24

+ 22
- 7
dddsample/pom.xml Datei anzeigen

@@ -1,5 +1,4 @@
1
-<?xml version="1.0" encoding="UTF-8"?>
2
-<project>
1
+<?xml version="1.0" encoding="UTF-8"?><project>
3 2
   <modelVersion>4.0.0</modelVersion>
4 3
   <groupId>se.citerus</groupId>
5 4
   <artifactId>dddsample</artifactId>
@@ -10,7 +9,14 @@
10 9
     Domain Driven Design implemented in Enterprise Java.
11 10
   </description>
12 11
   <url>http://sourceforge.net/projects/dddsample/</url>
13
-  <ciManagement />
12
+  <ciManagement/>
13
+  <repositories>
14
+    <repository>
15
+      <id>maven2-repository.dev.java.net</id>
16
+      <name>Java.net Repository for Maven</name>
17
+      <url>http://download.java.net/maven/2/</url>
18
+    </repository>
19
+  </repositories>
14 20
   <developers>
15 21
     <developer>
16 22
       <id>peba</id>
@@ -18,7 +24,7 @@
18 24
       <email>peter.backlund@citerus.se</email>
19 25
       <organization>Citerus</organization>
20 26
       <organizationUrl>http://www.citerus.se</organizationUrl>
21
-      <timezone>CET</timezone>
27
+      <timezone>GMT+1</timezone>
22 28
     </developer>
23 29
     <developer>
24 30
       <id>patrikfr</id>
@@ -26,7 +32,7 @@
26 32
       <email>patrikfr@users.sourceforge.net</email>
27 33
       <organization>Citerus</organization>
28 34
       <organizationUrl>http://www.citerus.se</organizationUrl>
29
-      <timezone>CET</timezone>
35
+      <timezone>GMT+1</timezone>
30 36
     </developer>
31 37
     <developer>
32 38
       <id>jeham</id>
@@ -34,7 +40,7 @@
34 40
       <email>jeham@users.sourceforge.net</email>
35 41
       <organization>Citerus</organization>
36 42
       <organizationUrl>http://www.citerus.se</organizationUrl>
37
-      <timezone>CET</timezone>
43
+      <timezone>GMT+1</timezone>
38 44
     </developer>
39 45
     <developer>
40 46
       <id>jorgen_falk</id>
@@ -48,6 +54,8 @@
48 54
   <licenses>
49 55
     <license>
50 56
       <name>MIT</name>
57
+      <url>http://www.opensource.org/licenses/mit-license.php</url>
58
+      <distribution>repo</distribution>
51 59
     </license>
52 60
   </licenses>
53 61
   <scm>
@@ -56,6 +64,7 @@
56 64
   </scm>
57 65
   <build>
58 66
     <plugins>
67
+      <!-- Compiler -->
59 68
       <plugin>
60 69
         <artifactId>maven-compiler-plugin</artifactId>
61 70
         <configuration>
@@ -64,6 +73,12 @@
64 73
           <encoding>UTF-8</encoding>
65 74
         </configuration>
66 75
       </plugin>
76
+
77
+      <!-- Jetty servlet container: http://jetty.mortbay.com/maven-plugin -->
78
+      <plugin>
79
+        <groupId>org.mortbay.jetty</groupId>
80
+        <artifactId>maven-jetty-plugin</artifactId>
81
+      </plugin>
67 82
     </plugins>
68 83
   </build>
69 84
   <dependencies>
@@ -91,7 +106,7 @@
91 106
     <dependency>
92 107
       <groupId>commons-lang</groupId>
93 108
       <artifactId>commons-lang</artifactId>
94
-      <version>20030203.000129</version>
109
+      <version>2.3</version>
95 110
     </dependency>
96 111
     <dependency>
97 112
       <groupId>commons-logging</groupId>

+ 0
- 52
dddsample/src/main/resources/applicationContext.xml Datei anzeigen

@@ -1,52 +0,0 @@
1
-<?xml version="1.0" encoding="UTF-8"?>
2
-<beans xmlns="http://www.springframework.org/schema/beans"
3
-	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
-	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
5
-
6
-	<!-- 
7
-		Properties
8
-	-->
9
-	<bean id="propertyConfigurer"
10
-		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
11
-		<property name="locations">
12
-			<list>
13
-				<value>classpath:jdbc.properties</value>
14
-				<value>classpath:log4j.properties</value>
15
-			</list>
16
-		</property>
17
-	</bean>
18
-
19
-	<!-- 
20
-		Beans
21
-	-->
22
-	<bean id="cargoRepository" class="se.citerus.dddsample.repository.CargoRepositoryInMem">
23
-	</bean>
24
-
25
-	<bean id="cargoService" class="se.citerus.dddsample.service.CargoServiceImpl">
26
-		<property name="cargoRepository" ref="cargoRepository" />
27
-	</bean>
28
-
29
-
30
-	<!-- 
31
-		<bean id="testDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
32
-		<property name="driverClassName" value="${jdbc.driverClassName}" />
33
-		<property name="url" value="${jdbc.url}" />
34
-		<property name="username" value="${jdbc.username}" />
35
-		<property name="password" value="${jdbc.password}" />
36
-		</bean>
37
-		
38
-		<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
39
-		<property name="dataSource" ref="testataSource" />
40
-		<property name="mappingResources">
41
-		<list>
42
-		<value>cargo.hbm.xml</value>
43
-		</list>
44
-		</property>
45
-		<property name="hibernateProperties">
46
-		<value>
47
-		hibernate.dialect=org.hibernate.dialect.HSQLDialect
48
-		</value>
49
-		</property>
50
-		</bean>
51
-	-->
52
-</beans>

+ 36
- 0
dddsample/src/main/resources/context-persistence.xml Datei anzeigen

@@ -0,0 +1,36 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+
3
+<beans  xmlns="http://www.springframework.org/schema/beans"
4
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
+        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
6
+
7
+  <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
8
+    <property name="location" value="classpath:jdbc.properties"/>
9
+  </bean>
10
+
11
+  <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
12
+    <property name="url" value="${jdbc.url}"/>
13
+    <property name="driverClassName" value="${jdbc.driverClassName}"/>
14
+    <property name="username" value="${jdbc.username}"/>
15
+    <property name="password" value="${jdbc.password}"/>
16
+  </bean>
17
+
18
+  <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
19
+    <property name="dataSource" ref="dataSource"/>
20
+    <property name="hibernateProperties">
21
+      <props>
22
+        <!-- These are properties that are common for test and production -->
23
+        <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
24
+        <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
25
+      </props>
26
+    </property>
27
+  </bean>
28
+
29
+  <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
30
+    <property name="sessionFactory" ref="sessionFactory"/>
31
+  </bean>
32
+
33
+  <bean id="cargoRepository" class="se.citerus.dddsample.repository.CargoRepositoryInMem">
34
+  </bean>
35
+
36
+</beans>

+ 16
- 0
dddsample/src/main/resources/context-service.xml Datei anzeigen

@@ -0,0 +1,16 @@
1
+<?xml version="1.0"?>
2
+
3
+<beans xmlns="http://www.springframework.org/schema/beans"
4
+       xmlns:tx="http://www.springframework.org/schema/tx"
5
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6
+       xsi:schemaLocation="
7
+        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
8
+        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
9
+
10
+  <tx:annotation-driven transaction-manager="transactionManager"/>
11
+
12
+  <bean id="cargoService" class="se.citerus.dddsample.service.CargoServiceImpl">
13
+    <property name="cargoRepository" ref="cargoRepository"/>
14
+  </bean>
15
+
16
+</beans>

+ 3
- 0
dddsample/src/main/resources/hibernate.properties Datei anzeigen

@@ -0,0 +1,3 @@
1
+hibernate.hbm2ddl.auto=create-drop
2
+hibernate.show_sql=false
3
+hibernate.format_sql=false

+ 1
- 1
dddsample/src/main/resources/jdbc.properties Datei anzeigen

@@ -1,4 +1,4 @@
1 1
 jdbc.driverClassName=org.hsqldb.jdbcDriver
2
-jdbc.url=jdbc:hsqldb:file:testdb
2
+jdbc.url=jdbc:hsqldb:file:target/dddsample
3 3
 jdbc.username=sa
4 4
 jdbc.password=

+ 0
- 2
dddsample/src/main/webapp/WEB-INF/dispatch-servlet.xml Datei anzeigen

@@ -3,8 +3,6 @@
3 3
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 4
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
5 5
 
6
-  <import resource="classpath:applicationContext.xml"/>
7
-
8 6
   <bean name="/start.html" class="se.citerus.dddsample.web.CargoTrackingController">
9 7
     <property name="sessionForm" value="true"/>
10 8
     <property name="commandName" value="trackCommand"/>

+ 9
- 0
dddsample/src/main/webapp/WEB-INF/web.xml Datei anzeigen

@@ -6,6 +6,15 @@
6 6
 
7 7
 <display-name>DDDSample</display-name>
8 8
 
9
+  <listener>
10
+    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
11
+  </listener>
12
+
13
+  <context-param>
14
+    <param-name>contextConfigLocation</param-name>
15
+    <param-value>classpath:context-*.xml</param-value>
16
+  </context-param>
17
+
9 18
   <servlet>
10 19
     <servlet-name>dispatch</servlet-name>
11 20
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

+ 0
- 52
dddsample/src/test/resources/applicationContext.xml Datei anzeigen

@@ -1,52 +0,0 @@
1
-<?xml version="1.0" encoding="UTF-8"?>
2
-<beans xmlns="http://www.springframework.org/schema/beans"
3
-	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
-	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
5
-
6
-	<!-- 
7
-		Properties
8
-	-->
9
-	<bean id="propertyConfigurer"
10
-		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
11
-		<property name="locations">
12
-			<list>
13
-				<value>jdbc.properties</value>
14
-				<value>log4j.properties</value>
15
-			</list>
16
-		</property>
17
-	</bean>
18
-
19
-	<!-- 
20
-		Beans
21
-	-->
22
-	<bean id="cargoRepository" class="se.citerus.dddsample.repository.CargoRepositoryInMem">
23
-	</bean>
24
-
25
-	<bean id="cargoService" class="se.citerus.dddsample.service.CargoServiceImpl">
26
-		<property name="cargoRepository" ref="cargoRepository" />
27
-	</bean>
28
-
29
-
30
-	<!-- 
31
-		<bean id="testDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
32
-		<property name="driverClassName" value="${jdbc.driverClassName}" />
33
-		<property name="url" value="${jdbc.url}" />
34
-		<property name="username" value="${jdbc.username}" />
35
-		<property name="password" value="${jdbc.password}" />
36
-		</bean>
37
-		
38
-		<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
39
-		<property name="dataSource" ref="testataSource" />
40
-		<property name="mappingResources">
41
-		<list>
42
-		<value>cargo.hbm.xml</value>
43
-		</list>
44
-		</property>
45
-		<property name="hibernateProperties">
46
-		<value>
47
-		hibernate.dialect=org.hibernate.dialect.HSQLDialect
48
-		</value>
49
-		</property>
50
-		</bean>
51
-	-->
52
-</beans>

+ 3
- 0
dddsample/src/test/resources/hibernate.properties Datei anzeigen

@@ -0,0 +1,3 @@
1
+hibernate.hbm2ddl.auto=create-drop
2
+hibernate.show_sql=true
3
+hibernate.format_sql=true

+ 1
- 1
dddsample/src/test/resources/jdbc.properties Datei anzeigen

@@ -1,4 +1,4 @@
1 1
 jdbc.driverClassName=org.hsqldb.jdbcDriver
2
-jdbc.url=jdbc:hsqldb:file:testdb
2
+jdbc.url=jdbc:hsqldb:mem:dddsample_test
3 3
 jdbc.username=sa
4 4
 jdbc.password=

+ 0
- 9
dddsample/src/test/resources/log4j.properties Datei anzeigen

@@ -6,14 +6,5 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender
6 6
 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
7 7
 log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n
8 8
 
9
-log4j.appender.logfile=org.apache.log4j.RollingFileAppender
10
-log4j.appender.logfile.File=${java.io.tmpdir}/dddsample.log
11
-log4j.appender.logfile.MaxFileSize=512KB
12
-# Keep three backup files.
13
-log4j.appender.logfile.MaxBackupIndex=3
14
-# Pattern to output: date priority [category] - message
15
-log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
16
-log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n
17
-
18 9
 # Mute some packages
19 10
 log4j.logger.org=warn