Questions tagged [applicationcontext]

The Spring `ApplicationContext` class

The Spring ApplicationContext class is the central interface to provide configuration to any Spring application.

869 questions
269
votes
6 answers

How to call a method after bean initialization is complete?

I have a use case where I need to call a (non-static) method in the bean only-once at the ApplicationContext load up. Is it ok, if I use MethodInvokingFactoryBean for this? Or we have a some better solution? As a side note, I use…
peakit
  • 28,597
  • 27
  • 63
  • 80
267
votes
22 answers

BeanFactory vs ApplicationContext

I'm pretty new to the Spring Framework, I've been playing around with it and putting a few samples apps together for the purposes of evaluating Spring MVC for use in an upcoming company project. So far I really like what I see in Spring MVC, seems…
matt b
  • 138,234
  • 66
  • 282
  • 345
245
votes
16 answers

Getting Spring Application Context

Is there a way to statically/globally request a copy of the ApplicationContext in a Spring application? Assuming the main class starts up and initializes the application context, does it need to pass that down through the call stack to any classes…
Joe Skora
  • 14,735
  • 5
  • 36
  • 39
210
votes
14 answers

How to change context root of a dynamic web project in Eclipse?

I developed a dynamic web project in Eclipse. I can access the app through my browser using the following URL: http://localhost:8080/MyDynamicWebApp I want to change the access URL to: http://localhost:8080/app To do so, I changed the context…
Amit
  • 33,847
  • 91
  • 226
  • 299
205
votes
5 answers

What is the difference between ApplicationContext and WebApplicationContext in Spring MVC?

What is the difference between Application Context and Web Application Context? I am aware that WebApplicationContext is used for Spring MVC architecture oriented applications? I want to know what is the use of ApplicationContext in MVC…
Sumit Trehan
  • 3,985
  • 3
  • 27
  • 42
85
votes
24 answers

Spring cannot find bean xml configuration file when it does exist

I am trying to make my first bean in Spring but got a problem with loading a context. I have a configuration XML file of the bean in src/main/resources. I receive the following IOException: Exception in thread "main" …
dawrutowicz
  • 2,930
  • 2
  • 15
  • 19
78
votes
5 answers

How to add a hook to the application context initialization event?

For a regular Servlet, I guess you could declare a context listener, but for Spring MVC would Spring make this any easier? Furthermore, if I define a context listener and then would need to access the beans defined in my servlet.xml or…
teddy teddy
  • 3,025
  • 6
  • 31
  • 48
72
votes
1 answer

What is a NoSuchBeanDefinitionException and how do I fix it?

Please explain the following about NoSuchBeanDefinitionException exception in Spring: What does it mean? Under what conditions will it be thrown? How can I prevent it? This post is designed to be a comprehensive Q&A about occurrences of…
Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
71
votes
5 answers

How to inject ApplicationContext itself

I want to inject an ApplicationContext itself to a bean. Something like public void setApplicationContext(ApplicationContect context) { this.context = context; } Is that possible in spring?
mibutec
  • 2,929
  • 6
  • 27
  • 39
71
votes
1 answer

How do you reset Spring JUnit application context after a test class dirties it?

I'm using Spring 3.1.1.RELEASE, JUnit 4.8.1 and the HSQL 2.7.7 in-memory database. I have one test class annotated as @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({ "classpath:test-trainingSessionServiceContext.xml"…
Dave
  • 15,639
  • 133
  • 442
  • 830
67
votes
5 answers

How to access Spring context in jUnit tests annotated with @RunWith and @ContextConfiguration?

I have following test class @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"/services-test-config.xml"}) public class MySericeTest { @Autowired MyService service; ... } Is it possible to access…
Vladimir
  • 12,753
  • 19
  • 62
  • 77
47
votes
3 answers

Spring ApplicationListener is not receiving events

I have the following ApplicationListener: package org.mycompany.listeners; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextStartedEvent; public class MyApplicationListener implements…
Andrey Adamovich
  • 20,285
  • 14
  • 94
  • 132
43
votes
11 answers

Failed to load ApplicationContext from Unit Test: FileNotFound

I am creating a Maven Spring project, which includes MVC, Data and Security. My Spring applicationContext-*.xml files are located at \src\main\resources\spring\ My TestCase is placed at \src\test\java\my\package\controller\ and its code…
Manu
  • 4,019
  • 8
  • 50
  • 94
42
votes
2 answers

Initializing Spring bean from static method from another Class?

I was trying to create Hibernate Validator bean, and run into this problem creating a bean from static factory method in another Class. I found a Spring way to get my Validator bean initialized (solution at the bottom), but the problem itself…
Spaideri
  • 514
  • 1
  • 5
  • 10
42
votes
5 answers

ApplicationContext and ServletContext

I get confused between the two ApplicationContext and ServletContext when it comes to Spring MVC Application. I know that There is just only One ApplicationContext per Spring Web Application and there is also just only One ServletContext per web…
Raleigh
  • 457
  • 1
  • 4
  • 3
1
2 3
57 58