2013-06-25 1 views
3

DB의 일부 엔티티 필드를 JSON으로 저장해야합니다. 즐겨 찾는 해결책은 사용자 정의 최대 절전 모드 UserType을 정의하는 것입니다.Hibernate UserType 객체에 빈 삽입하기?

JSON 변환기 (Jackson)는 싱글 톤으로 사용하도록 권장하지만 최대 절전 모드 자체는 사용자 지정 UserType 개체를 만듭니다. 커스텀 Hibernate UserType 객체에 스프링으로 정의 된 JSON 컨버터 빈을 어떻게 삽입 할 수 있습니까?

답변

0

솔루션은 @Configurable을 사용하고 있기 때문에 속성 객체를 inten하는 스프링 컨테이너가 아니더라도 자동으로 속성 객체를 사용할 수 있습니다. http://static.springsource.org/spring/docs/3.2.3.RELEASE/spring-framework-reference/html/aop.html#aop-atconfigurable

코드 exemple :

@Configurable 
public class CSessionImpl implements CSessionOperations { 


    private Touriste touriste; 

    @Inject 
    private Office office; 

    @Inject 
    private OTmanager manager; 

    @Inject private ScheduledExecutorService executorService; 

    private ScheduledFuture<Void> schedule; 

    @PostConstruct 
    private void replanifierMiseHorsLigne(){ 
     if(schedule != null){ 
      schedule.cancel(false); 
     } 
     schedule = executorService.schedule(new Callable<Void>() { 
      @Override 
      public Void call() t 

이 CSessionImpl 때이 exemble에서 볼

봄 설명서를 참조하십시오. < init>은 @Inject가 연결된 유인물을 호출합니다.

당신은 beans.xml 환경에 추가 nedd :

<build> 
    <finalName>OTLogiciel</finalName> 
    <plugins> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>aspectj-maven-plugin</artifactId> 
      <version>1.4</version> 
      <executions> 
       <execution> 
        <id>compile</id> 
        <configuration> 
         <showWeaveInfo>true</showWeaveInfo> 
         <source>${java-version}</source> 
         <target>${java-version}</target> 
         <verbose>false</verbose> 
         <outxml>true</outxml> 
         <aspectLibraries> 
          <aspectLibrary> 
         <groupId>org.springframework</groupId> 
         <artifactId>spring-aspects</artifactId> 
          </aspectLibrary> 
         </aspectLibraries> 
        </configuration> 
        <goals> 
         <goal>compile</goal> 
         <goal>test-compile</goal> 
        </goals> 
       </execution> 
      </executions> 
      <dependencies> 
       <dependency> 
        <groupId>javax.persistence</groupId> 
        <artifactId>persistence-api</artifactId> 
        <version>1.0</version> 
        <optional>true</optional> 
       </dependency> 
       <dependency> 
        <groupId>org.aspectj</groupId> 
        <artifactId>aspectjweaver</artifactId> 
        <version>${org.aspectj-version}</version> 
       </dependency> 
       <dependency> 
        <groupId>org.aspectj</groupId> 
        <artifactId>aspectjtools</artifactId> 
        <version>${org.aspectj-version}</version> 
       </dependency> 
      </dependencies> 
     </plugin> 
:

<context:spring-configured/> 

당신은 또한 컴파일 타임 또는 런타임에 직조 수행해야 컴파일 시간 짜기위한 받는다는에 대한

Exemple

eclispe를 사용하는 경우 "ApectJ 개발 도구"도 설치해야합니다.

관련 문제