java - Location of spring-context.xml -


when run application on tomcat spring-context.xml file located @

/web-inf/spring-context.xml

this ok. running junit test have supply location of spring-test-context.xml this:

@contextconfiguration(locations={"classpath:/spring-test-context.xml"}) 

the way works if file located in

/src/spring-context.xml

how can application find spring-context files in same location? works junit testes , deployed on tomcat?

i tried , gave me alot of errors not finding beans, didn't couldn't find file..

classpath:/web-inf/spring-test-context.xml 

as duffymo hinted at, spring testcontext framework (tcf) assumes string locations in classpath default. details, see javadoc contextconfiguration.

note, however, can specify resources in file system either absolute or relative path using spring's resource abstraction (i.e., using "file:" prefix). can find details on in javadoc modifylocations() method in spring's abstractcontextloader.

so example, if xml configuration file located in "src/main/webapp/web-inf/spring-config.xml" in project folder, specify location relative file system path follows:

@contextconfiguration("file:src/main/webapp/web-inf/spring-config.xml") 

as alternative, store spring configuration files in classpath (e.g., src/main/resources) , reference them via classpath in spring mvc configuration -- example:

<context-param>     <param-name>contextconfiglocation</param-name>     <param-value>classpath:/spring-config.xml</param-value> </context-param>  <listener>     <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> 

with approach, test configuration (note leading slash denotes resource in root of classpath):

@contextconfiguration("/spring-config.xml") 

you might find context configuration xml resources section of reference manual useful.

regards,

sam

(author of spring testcontext framework)


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -