0

To begin with, I have to say that I'm totally new in spring, my first task was to change application context. I think it should be placed in *.xml files, but can' find the field. I've google it as well, but didn' find any solution. Probably poor searcher :(.

Ajinkya
  • 22,324
  • 33
  • 110
  • 161
iie
  • 501
  • 4
  • 8
  • 26

2 Answers2

1
ApplicationContext context = new ClassPathXmlApplicationContext("context.xml");    

It will load the context from context.xml file (context.xml should be present in classpath).
You can create new Applicationcontext by passing desired XML file as parameter to constructor.

Ajinkya
  • 22,324
  • 33
  • 110
  • 161
  • and there is no other way? I thought it was placed in some file which already exists – iie Apr 10 '12 at 19:44
  • 1
    @iie: Your application must be using some context files. If you want to change the context you can use code mentioned above. If you want to change something in existing context just update the existing context configuration file. – Ajinkya Apr 10 '12 at 19:58
1

There are not much informations, but if you are working on an web application with spring, you can set up the context in your web.xml:

<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param> 
Martin Röbert
  • 664
  • 8
  • 25
  • sorry, I hadn't add this, yes - this is an web application. So by changing the value of I'm changing the application context? – iie Apr 11 '12 at 07:30
  • 1
    Regarding the api: yes. see the [api docs here](http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/web/context/ContextLoader.html). Furthermore you can have a look onto [this blog](http://viralpatel.net/blogs/2205/change-spring-servlet-filename-configuration) – Martin Röbert Apr 11 '12 at 07:54