0

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.

4 Answers 4

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

You can try that same prefix if that's what you need. ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:config.xml");
0

If your config xml is in package com.anywhere.here then try this:

ApplicationContext myAppContext = new ClassPathXmlApplicationContext("com/anywhere/here/config.xml"); 

Comments

0

In case of maven project, right click on project-maven-update project, this helped me solve my issue.

Comments

-2

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.