0

I have created a spring MVC application. I'm working on spring security concepts. So I've created a context configuration file name webbsite-security.xml and I've given the same file location in the context configuration path. The application fails due to an exception stating that FILENOTFOUNDEXCEPTION(applicationContext.xml not found). Is it necessary that a file named applicationContext.xml should exits even though we use some other configuration files.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
vvekselva
  • 803
  • 3
  • 17
  • 34

1 Answers1

1

Why would you want to call it anything else, it would go against the default standard spring way fo doing things. Just import the relevant config files into the default app context xml.

But if you want change it you must specifiy in your web.xml the following :

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/whatevever.xml</param-value>
</context-param> 

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
NimChimpsky
  • 46,453
  • 60
  • 198
  • 311
  • I don't believe the filename of app context has ever been something we should follow that strictly. In my previous projects, I have never follow this default name, and everything is fine. – Adrian Shum Jul 17 '12 at 09:25
  • @AdrianShum you are right, but it still seems a weird thing to do to me. – NimChimpsky Jul 17 '12 at 09:26
  • Not that weird in fact. There are many case you want to use another file name to align to guideline of company, or to name it in a way that better describe what it does – Adrian Shum Jul 17 '12 at 09:35
  • @AdrianShum it instantiates a new application Context, what filename could better describe that ? I am sure some companies do, doesn't make them right. – NimChimpsky Jul 17 '12 at 09:37
  • for example, in case of application context splitted into several file, calling it applicationContext-bootstrap.xml may be a better description of its use. Also, if your application can be started up using different means (as standalone app, or as a web app), it is reasonable to have different bootstrap app context xml. Giving different names to them is nothing to be surprised of. And, from my experience using Spring from 1.x era, Spring has never push applicationContext.xml as a convention that developers are suggested to follow. I don't get why you are so against using different name :P – Adrian Shum Jul 17 '12 at 09:43
  • After some research, I found what is the problem over the issue, Please correct if I'm wrong, In my web.xml I've created a listener viz., ContextLoaderListener and the context param as contextConfigLocation /WEB-INF/securityContext.xml The dispatcher servlet loads securitycontext.xml using the context param and the listerner searches for the applicationContext.xml. But my webapp doesn't any applicationContext.xml so FileNotFoundException is thrown – vvekselva Jul 23 '12 at 06:02