开发者

spring loading context files with maven project

开发者 https://www.devze.com 2023-03-31 00:50 出处:网络
I use maven build in my application. I have package like: 1> sr开发者_如何学运维c/test/java// for Test application

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

1> sr开发者_如何学运维c/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?


You need to move

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

to

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.

References

  • Maven - introduction to the standard directory layout
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号