Quantcast
Channel: Spring Community Forums - Data
Viewing all articles
Browse latest Browse all 297

Inject EntityManager in a custom PropertyPlaceHolderConfigurer

$
0
0
Hello,

I would like to implements a custom PropertyPlaceholderConfigurer to load my properties from a database.

So I just add a Bean like this :

Code:

@Repository
@Transactional
public class DatabasePropertyPlaceholderConfigurerImpl extends PropertyPlaceholderConfigurer {

    @PersistenceContext
    private EntityManager em;

    public DatabasePropertyPlaceholderConfigurerImpl() {
        super();
        setPlaceholderPrefix("${");
    }

    @Override
    protected void loadProperties(final Properties props) throws IOException {
      // DO STUFF HERE WITH ENTITYMANAGER TO LOAD THE PROPS
    }
}

The problem is that the entitymanager is null !

The configuration is the same for my DAO's and it works!

I've just noticed that if I remove "extends PropertyPlaceholderConfigurer", the entitymanager is well injected.

Can someone tell me why it doesn't work in a PropertyPlaceholderConfigurer?

Thank you.

Stéphane

Viewing all articles
Browse latest Browse all 297

Trending Articles