Advertisement
drSdGdBy

beanFactory configuration

Jul 27th, 2020
1,054
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. public class Application {
  2.  
  3.     private static final Logger logger = LoggerFactory.getLogger(Application.class);
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         var factory = new DefaultListableBeanFactory();
  8.         var reader = new XmlBeanDefinitionReader(factory);
  9.         reader.loadBeanDefinitions(new ClassPathResource("my-beans.xml"));
  10.  
  11.         var cfg = new PropertyPlaceholderConfigurer();
  12.         cfg.setLocation(new ClassPathResource("database.properties"));
  13.         cfg.postProcessBeanFactory(factory);
  14.  
  15.         var dataSource = (SimpleDriverDataSource) factory.getBean("dataSource");
  16.  
  17.         logger.info("Url: {}", dataSource.getUrl());
  18.         logger.info("User name: {}", dataSource.getUsername());
  19.         logger.info("Password: {}", dataSource.getPassword());
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement