1. Intro

1.1 Maven dependency

<repositories>
    ...
    <repository>
        <id>springfield-mvn-repo</id>
        <url>https://raw.github.com/u2ware/springfield/mvn-repo/</url>
    </repository>
    ...
</repositories>
	        
<dependencies>
    ...
    <dependency>
        <groupId>com.u2ware</groupId>
        <artifactId>springfield</artifactId> 
        <version>1.5.0</version> 
    </dependency>
    ...
</dependencies>
		

1.2 @Springfield

@Springfield(
		strategy=Strategy.JPA,
		entity=Class.class,
		identity={"...","..."},
		topLevelMapping="...",
		methodLevelMapping={"...","..."},
		attributesCSV="key1={value1},key2={value2}, ..."
)
@Entity
public class Foo{
	
	@Id
	private String id;
	
	...
}		
		

Table 1.1.  @Springfield Attributes

namerequiredassignabledescription
strategyoptional Springfield.Strategy bean auto register strategy...
entityoptionaljava.lang.ClassEntity class
identityoptionaljava.lang.String[]Identity property names
topLevelMappingoptionaljava.lang.StringHandler mapping path
methodLevelMappingoptionaljava.lang.String[]Handler mapping path
attributesCSVoptionaljava.lang.Stringview options

1.3 <springfield:modules>

<?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:springfield="http://www.u2ware.com/schema/springfield"                                                          (1)
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.u2ware.com/schema/springfield                                                                             (1)
		http://www.u2ware.com/schema/springfield/u2ware-springfield.xsd">                                                    (1)

	<springfield:modules 
		properties-ref="...."
		base-package="com.yourcompany.yourproject" 
		default-strategy="..."
		data-source-ref="..."
		entity-manager-factory-ref="..."
		session-factory-ref="..."
		sql-session-factory-ref="..."
	/>

	...
</beans>
			

1

springfield namesapce & schemaLocation

Table 1.2. <springfield:modules> Attributes

namerequiredassignabledescription
properties-refoptionaljava.util.PropertiesProperties Reference Bean Name
base-packagerequiredjava.lang.Stringroot package for scan @Springfield
default-strategyoptional Springfield.Strategy @Springfield default bean auto register strategy
data-source-refoptionaljavax.sql.DataSourcedataSource Reference Bean Name
entity-manager-factory-refoptionalorg.springframework.orm.jpa.AbstractEntityManagerFactoryBeanJPA EntityManager Reference Bean Name
session-factory-refoptionalorg.springframework.orm.hibernate3.AbstractSessionFactoryBeanHibernate SessionFactory Reference Bean Name
sql-session-factory-refoptionalorg.mybatis.spring.SqlSessionFactoryBeanMybatis SessionFactory Reference Bean Name

1.4 Springfield Example

root-context.xml

<beans>  
	<jdbc:embedded-database id="yourDataSource" type="HSQL"/>  	
	
	<springfield:modules base-package="com.yourcompany.yourproject" 
			data-source-ref="yourDataSource"
	/>
</beans>
		

Foo.java

package com.yourcompany.yourproject.foo;

@Springfield
@Entity
public class Foo{
	@Id
	private String name;
	private Integer age;
	...
}
		

Bar.java

package com.yourcompany.yourproject.bar;

@Entity
public class Bar{
	@Id
	private Integer seq;
	...
}
		

BarSearch.java

package com.yourcompany.yourproject.bar;

@Springfield(
	entity=Bar.class,
	topLevelMapping="/a/b/c/d"
)
public class BarSearch{
	...
}