Spring MVC Sample base on Spring 2.5 Annotation

This sample is based on Spring 2.5 Annotation that using @Controller(and another MVC annotation), @Repository, etc…

Yet now implemented few function, but I have plan to update in the future.

I wnat to be of help you!

Source : Go to Google Code

ps.  get source by svn

ps.  some text is korean

Must be required getter / setter method for hibernate’s Entity?

No.

Hibernate must not require getter/setter method for Entity if using that field access type.

We possibly configure field access type

1. <hibernate-mapping default-access=”field|property|ClassName” >

2. <property access=”field|property|ClassName” >

3. @AccessType(“field|property|ClassName”)

If you using field access type, only can use field.

@Entity
@AccessType(“field”)
public class EntityExample {

@Id
private String id;

@ManyToOne
private AnotherEntity friend;


}

This time directly access to field by Reflection.

But consider from a different standpoint that problem why using getter/setter?

It may be considered point of view that how use Entity object.

If Entity is (rich) domain object, may require getter and setter method.

But Entity is only used to data container(or DTO), may not require setter method.

We had remove misunderstanding to certainly require getter/setter method when using Hibernate!

Is Domain Object need to declare to Spring bean?

I got a problem when implement DDD with Spring. This problem is “Is Domain Object need to declare to Spring bean?”.

What do you think this problem?

In past, I’m thought that Domain Object is not absolutely declared Spring Bean.

But I’m confused that implement it example for DDD with Spring.

Because Domain Object had Data and Behavior(Business Logic), it is need to directly dependencies with other layer class(specific Repository or Infrastructure layer).


class Board {
private BoardRepository repository;
public void insert() {
repository.insert(this);
}
...
}

Once I progress toward declaration to Bean.

This is point of problem. If we use ORM as Hibernate, Domain Object take the responsibility of Entity and Spring’s Bean at a time.

@Entity
@SequenceGenerator(name = "BoardId_Seq", sequenceName = "BoardId_Seq")
class Board {
...
}

Because creation of Domain Object is executed to inner ORM, need to additional code for DI.

For example,

class BoardServiceFacade ...{
...
public Long insertBoard(Board board) {
Board boardBean = domainFactory.newBoard(board);
boardBean.insert();
return boardBean.getId();
}
}

class DomainFactory ...{
public Board newBoard(Board board) {
Board boardBean = newInitializedBoard(board);
return boardBean;
}
}

Work flow is next for persist to Board instance :

1. insertBoard method called with Board instance that is got Client(layer).
2. domainFactory.newBoard() called with Board instance
3. create new Spring’s Bean instance(this bean has prototype bean scope) with initialized(resolved?) dependencies.
4. domain object’s value is copied to created Spring’s Bean from got instance from Client.
finally, Board instance that Spring’s Bean do persist method(insert()).

Opps. very complexity..

This complexity is caused by declared to Spring’s Bean for Domain Object.

If Domain Object is not declared Spring’s Bean, it’s code is not necessity!

I found very elegance solution in this article.

@Configuarble is introduced Spring 2.0. This annotation is possibe to injection of dependenies only add it by container.

@Configurable
...
class Board {
private BoardRepository repository;
public void insert() {
repository.insert(this);
}
...
}

very nice and very convenience.

reference article : Spring framework and DDD(Domain-Driven Design) – for korean.

I want to enter for Spring Experience 2008.

Spring Experience 2007 is held in Florida at December 12-15 .

Only One man is participating to this conference for the second straight year(or more years?^^)

I’m not went to abroad once, But I want to go to conference-Spring Experience 2008- at next year.

I’m anticipating cost that $2,700… and saving the money for participating conference from now.

I must participating conference for learn  their passion!