Skip to content

Enables simple enriching of objects in spring-projects

License

Notifications You must be signed in to change notification settings

avides/spring-enricher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spring-enricher

Maven Central Build Nightly build Coverage report Quality Gate Technical dept

Maven

<dependency>
    <groupId>com.avides.spring</groupId>
    <artifactId>spring-enricher</artifactId>
    <version>2.0.0</version>
</dependency>

Example

@Configuration
@EnableEnriching
public class EnricherConfiguration
{
}

@Service
public class CustomerService
{
    @Autowired
    private CustomerRepository customerRepository;

    @Enriched
    public Customer getCustomer(long id)
    {
        return customerRepository.getCustomer(id);
    }

    @Enriched
    public List<Customer> getCustomers()
    {
        return customerRepository.getCustomers();
    }
}

@Component
public class CustomerEnricher extends AbstractEnricher<Customer>
{
    @Autowired
    private AddressService addressService;

    public CustomerEnricher()
    {
        super(Customer.class);
    }

    @Override
    public void doEnrich(Customer customer)
    {
        customer.setAddresses(addressService.getAddresses(customer.getId()));
    }
}

@Component
public class CustomerOutput
{
    @Autowired
    private CustomerService customerService;

    public void outputCustomers()
    {
        for (Customer customer : customerService.getCustomers())
        {
            System.out.println(customer);
        }
    }

    public void outputCustomer(long id)
    {
        System.out.println(customerService.getCustomer(id));
    }
}