I need to execute SQL script before PropertyPlaceholderConfigurer is initialized in Spring’s context, as soon as application properties are stored in the database and this script should insert them. But currently placeholder is initialized earlier, which leads to errors.
Is there a way to execute <jdbc:initialize-database data-source="dataSource" ... before <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" ... in Spring?
Or is there a way to initialize placeholderConfig bean later? I tried to use depends-on, lazy-init attributes for this bean, but it didn’t help. Thanks in advance.
Here is how I solved that. I created a class
Initializer. This class in its constructor executes plain old sql statements (java.sql.Statement), creates table (if it doesn’t exist), and inserts properties (if they are not there). ThedataSourcebean is passed in the context to this constructor, andplaceholderConfigbean usesdepends-on="initializerBean". So, properties appear in the database before they are used.