13.07.2015 Views

Spring JavaConfig Reference Guide - Spring Web Services - Parent ...

Spring JavaConfig Reference Guide - Spring Web Services - Parent ...

Spring JavaConfig Reference Guide - Spring Web Services - Parent ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Quick start3.2. Create bean definitions@Configurationpublic class ApplicationConfig {@Beanpublic TransferService transferService() {return new TransferServiceImpl(accountRepository());}@Beanpublic AccountRepository accountRepository() {return new JdbcAccountRepository(dataSource());}}@Beanpublic DataSource dataSource() {return new DriverManagerDataSource(...);}3.3. Retrieve bean instancesLet's create a very basic, command-line application to allow users to transfer money from one account toanother.public class SimpleTransferApplication {public static void main(String... args) {double amount = new Double(args[0]);int sourceAcctId = new Integer(args[1]);int destAcctId = new Integer(args[2]);}}<strong>JavaConfig</strong>ApplicationContext context = new <strong>JavaConfig</strong>ApplicationContext(ApplicationConfig.class);TransferService transferService = context.getBean(TransferService.class);transferService.transfer(300.00, sourceAcctId, destAccountId);3.4. SummaryThat's it! You're now ready for Part II, “API <strong>Reference</strong>”, where you'll walk through each of the features of<strong>Spring</strong> <strong>JavaConfig</strong>.<strong>Spring</strong> <strong>JavaConfig</strong> 9

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!