Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

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

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top