Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Using AspectJ To Dependency Inject Domain Objects With Spring

DZone's Guide to

Using AspectJ To Dependency Inject Domain Objects With Spring

·
Free Resource
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;

@Configurable
public abstract class Entity
  
    {
	
	@Autowired
	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 : 

-javaagent:~/.m2/repository/org/springframework/spring-instrument/3.0.2.RELEASE/spring-instrument-3.0.2.RELEASE.jar


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

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}