package example.u2ware.springfield.part3.step2; import lombok.Getter; import lombok.Setter; import lombok.ToString; import com.u2ware.springfield.config.Springfield; import com.u2ware.springfield.config.Springfield.Strategy; import com.u2ware.springfield.repository.QueryMethod; import example.u2ware.springfield.part1.step2.JpaBean; @Springfield( strategy=Strategy.JPA, entity=JpaBean.class ) @QueryMethod("findByIdAndPasswordOrderByNameDesc") public @ToString class Custom { private @Getter @Setter Integer id; private @Getter @Setter String password; }
package example.u2ware.springfield.part3.step2; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.u2ware.springfield.domain.EntityPageable; import com.u2ware.springfield.repository.EntityRepository; import com.u2ware.springfield.service.EntityServiceImpl; import example.u2ware.springfield.part1.step2.JpaBean; @Service public class CustomService extends EntityServiceImpl<JpaBean, Custom>{ @Autowired public CustomService( @Qualifier("jpaBeanRepository")EntityRepository<JpaBean, Integer> r) { super("jpaBeanRepository", r); } @Override @Transactional public Iterable<JpaBean> findForm(Custom request, EntityPageable pageable) { logger.debug("Overide findForm "); return super.findForm(request, pageable); } }
@Springfield 선언으로 다음 3개의 Bean 이 자동 생성, 등록 된다.
bean id | bean type | implements type |
"customController" | EntityController<JpaBean, Custom> | com.u2ware.springfield.controller. EntityHandler |
"customService" | EntityService<JpaBean, Custom> | example.u2ware.springfield.part3.step2. CustomService |
"jpaBeanRepository" | EntityRepository<JpaBean, Integer> | com.u2ware.springfield.repository.jpa. EntityJpaRepository |
자동생성된 빈은 다음과 같이 하위 Layer 의 Bean 을 주입받아서 의존 관계를 갖는다.
"customController" <- "customService" <- "jpaBeanRepository"
<context:component-scan base-package="example.u2ware.springfield" />