How to get and set Spring's Autowired object?

I am implementing JSF + Spring integrated web app, I have several service classes like below:

@Service
@Transactional
public class AccountService
{
    @Autowired
    private AccountRepository accountRepository;

    public AccountRepository getRepository()
    {                   
        return accountRepository;
    }

    public Account insertOrUpdate(Account entity) 
    {
        return accountRepository.save(entity);
    }

    public Account findOne(Account entiti)
    {
        return accountRepository.findOne(entiti.getId());
    }
    //some other methods
}

I wanted to implement a base class which contains common methods for all service classes like below:

@Service
@Transactional
public class BaseService
{
    JpaRepository repository;

    public void setRepository(JpaRepository repository)
    {
        this.repository = repository;
    }

    public BaseEntity insertOrUpdate(BaseEntity entity)
    {
        return (BaseEntity) repository.save(entity);
    }

    public BaseEntity findOne(BaseEntity entity)
    {
        return (BaseEntity) repository.findOne(entity.getId());
    }
}

But the problem here is how to autowired the repository dynamically? I have tried to set the repository from subclass like below but doesn’t works. it will cause NullPointerException when I use the repository object in super class. Any recommendation on how to achieve this?

@Service
@Transactional
public class AccountService extends BaseService
{
    @Autowired
    private AccountRepository accountRepository;

    public AccountService()
    {
        super.setRepository(accountRepository);
    }
}

if you want to get and set autowired object and use @Autowired annotation then you need to use annotation on classes link @Service, @RestController and use code <context:component-scan annotation-config=”true” base-package=”com.demo.test”/> and <context:annotation-config /> into ApplicationContaxt.xml file to scan the base package, this bass package scan use to scan the annotation. you can also use another way where you need to create the bean using java class configuration and create the object for autowire. in java configuration class you need to use @Configuration annotation. you can find below sample code for configuration where i am create bean for modelMapper classs

@Configuration
public class ModelMapperConfig {

@Bean(name = "modelMapper")
public ModelMapper getModelMapper() {
    ModelMapper modelMapper = new ModelMapper();
    return modelMapper;
}

@Bean(name = "modelMapperWithConverter")
public ModelMapper getModelMapperWithConverter() {
    ModelMapper modelMapper = new ModelMapper();
    return modelMapper;
}

you can also create bean from xml clas, you need to create bean into ApplicationContacxt.xml. you can find sample code below:

 <bean id = "advertisementRepo" class = "com.amstech.mayal.demo.test.AdvertisementRepo" />