PAPRestConfig extends WebMvcConfigurerAdapter { @PostConstruct public void init() { Properties prop = new Properties(); try (InputStream input = new FileInputStream("xacml.pap.properties")) { prop.load(input); setDbDriver(prop.getProperty("javax.persistence.jdbc.driver")); setDbUrl(prop.getProperty("javax.persistence.jdbc.url")); setDbUserName(prop.getProperty("javax.persistence.jdbc.user")); PeCryptoUtils.initAesKey(prop.getProperty(XacmlRestProperties.PROP_AES_KEY)); setDbPassword(PeCryptoUtils.decrypt(prop.getProperty("javax.persistence.jdbc.password"))); } catch (Exception e) { LOGGER.error("Exception Occured while loading properties file" + e); } }  @PostConstruct void init(); @Bean(name = "dataSource") DataSource getDataSource(); @Autowired @Bean(name = "sessionFactory") SessionFactory getSessionFactory(DataSource dataSource); @Autowired @Bean(name = "transactionManager") HibernateTransactionManager getTransactionManager(SessionFactory sessionFactory); static String getDbDriver(); static void setDbDriver(String dbDriver); static String getDbUrl(); static void setDbUrl(String dbUrl); static String getDbUserName(); static void setDbUserName(String dbUserName); static String getDbPassword(); static void setDbPassword(String dbPassword);  }
@Test public void testInit() { String driver = "org.mariadb.jdbc.Driver"; String url = "jdbc:mariadb: + "true&sessionVariables=max_statement_time=30"; String user = "policy_user"; String password = "policy_user"; PAPRestConfig config = new PAPRestConfig(); config.init(); assertEquals(PAPRestConfig.getDbDriver(), driver); assertEquals(PAPRestConfig.getDbUrl(), url); assertEquals(PAPRestConfig.getDbUserName(), user); assertEquals(PAPRestConfig.getDbPassword(), password); BasicDataSource source = (BasicDataSource) config.getDataSource(); assertEquals(source.getDriverClassName(), driver); assertEquals(source.getUrl(), url); assertEquals(source.getUsername(), user); assertEquals(source.getPassword(), password); SessionFactory factory = config.getSessionFactory(source); assertEquals(factory.isClosed(), false); HibernateTransactionManager manager = config.getTransactionManager(factory); assertEquals(manager.getSessionFactory(), factory); }