4. Code Example

This is the other remoting service previously mentioned. It's picked up by the context:component-scan because of the Service annotation and exposed as a Flex remoting service because of the RemotingDestination annotation. The service exposed is 'personService' based on the class name, but if a value could be passed into the Service annotation to expose it under a different name (ex: @Service("otherService")). To explicitly expose or hide methods the annotations RemotingInclude and RemotingExclude can be used.

[Note]Note

Trying to pass the Person instance returned from a remote request directly into the Person DAO's delete would caused an error since it's missing information woven into the class by the JPA implementation for the one to many relationship with Address.

Example 1. PersonService

                
@Service
@RemotingDestination
public class PersonService {

    private final PersonDao personDao;

    /**
     * Constructor
     */
    @Autowired
    public PersonService(PersonDao personDao) {
        this.personDao = personDao;
    }

    /**
     * <p>Deletes person.</p>
     * 
     * <p><strong>Note</strong>: Passing back the person 
     * from the Flex client causes a problem with Hibernate.</p>
     */
    public void remove(int id) {
        Person person = personDao.findPersonById(id);
        
        personDao.delete(person);
    }
    
}