Reputation: 13510
For my simple maven project this doesn't work:
ApplicationContext context = new ClassPathXmlApplicationContext("config.xml");
config.xml
is resided at the same class level
How,actually,add config.xml to classpath?
note: my project is a lib,if I do the same in other web project with configuration in
web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:config.xml</param-value>
</context-param>
that it works OK
Here I needn't web.xml, just correct classpath.
Upvotes: 0
Views: 9424
Reputation: 1
In case of maven project, right click on project-maven-update project, this helped me solve my issue.
Upvotes: 0
Reputation: 1
Please do This code - it worked
AbstractApplicationContext context= new ClassPathXmlApplicationContext("spring-config.xml");
o/w: Delete main method class and recreate it while recreating please uncheck Inherited abstract method its worked
Upvotes: -2
Reputation: 483
If your config xml is in package com.anywhere.here then try this:
ApplicationContext myAppContext = new ClassPathXmlApplicationContext("com/anywhere/here/config.xml");
Upvotes: 0
Reputation: 5123
When you enter classpath*:config.xml
, the classpath*
is a wild card indicates that you want to load every file matching config.xml
on the entire classpath, not just the single file config.xml
. This may be why your solution is working otherwise.
When instantiating a new ClassPathXmlApplicationContext
, try giving the full classpath as an argument: com\sergionni\myproj\config.xml
.
Upvotes: 3