25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Chapter 6 ■ Using Resource Files<br />

Listing 6-8. MyDocumentsWithResourceLoaderInjectionTest.java<br />

package com.apress.isf.spring.test;<br />

import static org.junit.Assert.assertNotNull;<br />

import org.junit.Before;<br />

import org.junit.Test;<br />

import org.slf4j.Logger;<br />

import org.slf4j.LoggerFactory;<br />

import org.springframework.context.support.ClassPathXmlApplicationContext;<br />

import com.apress.isf.spring.views.ResourceLoaderMenu;<br />

public class MyDocumentsWithResourceLoaderInjectionTest {<br />

private static final Logger log =<br />

LoggerFactory.getLogger(MyDocumentsWithResourceLoaderInjectionTest.class);<br />

private ClassPathXmlApplicationContext context;<br />

@Before<br />

public void setup(){<br />

context = new ClassPathXmlApplicationContext("META-INF/spring/<br />

mydocuments-resourceloader-injection-context.xml");<br />

}<br />

}<br />

@Test<br />

public void testMenu() {<br />

log.debug("Calling the Menu as Resourceloader Injection:");<br />

ResourceLoaderMenu menu = context.getBean(ResourceLoaderMenu.class);<br />

assertNotNull(menu);<br />

menu.printMenu("classpath:META-INF/data/menu.txt");<br />

}<br />

you should have the same result.:<br />

2014-04-23 12:20:43,127 DEBUG [main] Calling the Menu as Resource Injection:<br />

Welcome to My Documents<br />

1. Show all Documents<br />

2. Show all Document's Types<br />

3. Search by Type<br />

4. Quit<br />

Using Property Files<br />

The <strong>Spring</strong> <strong>Framework</strong> can help you read properties files that can contain sensitive data such as username,<br />

passwords, URL connections, etc. This feature allows you to separate this sensitive data from your XML configuration<br />

files, so it will be easy to deploy applications using the correct properties. A simple use case will have different<br />

properties files for different environments such as TEST, QA, and Production.<br />

67

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

Saved successfully!

Ooh no, something went wrong!