archivos de contexto de carga de primavera con el proyecto maven

I use maven build in my application. I have package like:

1> src/test/java   // for Test application
2> src/main/java   // code 
3> src/main/resource  // resource files

at 1> i have written a Test file as:

public void testLoginDetails() {
    new ClassPathXmlApplicationContext(
                new String[] { "/com/home/app/Home-ctx.xml" });

Home-ctx is available at 2> ie src/main/java/com/home/app/Home-ctx.xml

but when i run the application I am getting following common error:

Caused by: java.io.FileNotFoundException: class path resource [com/home/app/Home-ctx.xml] cannot be opened because it does not exist
    at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158)

I know this is classpath problem for xml file loading. How can I solve this?

preguntado el 27 de agosto de 11 a las 22:08

1 Respuestas

Necesitas moverte

src/main/java/com/home/app/Home-ctx.xml

a

src/main/resources/com/home/app/Home-ctx.xml

Classpath resources need to go in a resources folder - currently you've got them under a java folder, which is for sources, not resources.

If the resource is used only for testing, it should live in src/test/resources. For production resources, they go under src/main/resources.

Referencias

Respondido 28 ago 11, 02:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.