25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 6 ■ Using Resource Files<br />

}<br />

}<br />

while (scanner.hasNext()) {<br />

out.println(scanner.nextLine());<br />

}<br />

scanner.close();<br />

stream.close();<br />

}catch(IOException e){<br />

e.printStackTrace();<br />

}<br />

Next, Listing 6-4 shows your XML configuration. And the important part to remember is the property of your<br />

“menu” bean that points to your menu.txt file, located under src/resources/META-INF/data folder.<br />

Listing 6-4. mydocuments-resource-injection-context.xml<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Listing 6-5 shows the unit test that will load the mydocuments-resource-injection-context.xml configuration file<br />

(see Listing 6-4).<br />

Listing 6-5. MyDocumentsWithResourceInjectionTest.java<br />

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

import org.junit.Before;<br />

import org.junit.Test;<br />

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

import org.slf4j.Logger;<br />

import org.slf4j.LoggerFactory;<br />

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

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

public class MyDocumentsWithResourceInjectionTest {<br />

private static final Logger log =<br />

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

private ClassPathXmlApplicationContext context;<br />

@Before<br />

public void setup(){<br />

64

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

Saved successfully!

Ooh no, something went wrong!