Over a million developers have joined DZone.

Using AspectJ To Dependency Inject Domain Objects With Spring

Spring configuration: 

A base entity that use Hibernate: 

package come.package.domain;

import java.io.Serializable;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;

public abstract class Entity {
	private SessionFactory sessionFactory;
	public T getById(ID id) {
		return (T) getSession().get(getClass(), id);
	public ID save() {
		return (ID) getSession().save(this);

	protected Session getSession() {
		return sessionFactory.getCurrentSession();

JVM argument : 


More info: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/aop.html#aop-atconfigurable

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}