Questions tagged [applicationcontext]

The Spring `ApplicationContext` class

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

869 questions
33
votes
7 answers

Get application context returns null

The following schema has been touted as the way to get application context from anywhere within my android app. But sometimes doing MyApp.getContext() returns null. I tried changing the schema by removing static from getContext() so that I would do…
learner
  • 11,490
  • 26
  • 97
  • 169
31
votes
3 answers

How to tell spring to only load the needed beans for the JUnit test?

A simple question that might have an advanced answer. The Question: My question is, is there a way to instantiate only the classes, in your application context, needed for that specific JUnit test ? The Reason: My application context is getting…
SandMan
  • 555
  • 2
  • 6
  • 15
28
votes
2 answers

spring junit load application context for tests

I've got some XML files under my WEB-INF directory: lyricsBaseApp-servlet.xml hibernate.xml dataSource.xml beans.xml the servlet xml imports other xml files:
ducin
  • 25,621
  • 41
  • 157
  • 256
17
votes
1 answer

Create a spring boot application with multiple child contexts

I'm trying to create an application using spring boot with an hierarchical application context. My current main method looks like: public static void main(String[] args) { new SpringApplicationBuilder(TestApplication.class) …
17
votes
3 answers

Reload or refresh a Spring application context inside a test method?

I need to change the Spring profiles that are active in my applicationContext within a single method of my test class, and to do so I need to run one line of code before refreshing the contest because I am using a ProfileResolver. I have tried the…
David E
  • 888
  • 2
  • 8
  • 13
17
votes
4 answers

Ignore some classes while scanning PackagesToScan

I've a package (say packagesToScan) containing Classes that I wish to persist annotated with @Entity. While defining ApplicationContext configuration, I've done as…
TheKojuEffect
  • 20,103
  • 19
  • 89
  • 125
16
votes
1 answer

Why I must have a default constructor in a Spring configuration class annoted by the @Configuration annotation?

I am studying for Spring Core certification and, on the provided study stuff, I have this question but I can't give an answer to it. Why must you have to have a default constructor in your @Configuration annotated class? I don't declare any…
Java Surfer
  • 613
  • 3
  • 9
  • 13
16
votes
1 answer

Where can I find the example applicationContext.xml file

With Spring 3 distribution there was a project folder which was packaged in the distribution . This project folder had sample applicationContext.xml file which can be used . However when I have downloaded Spring 4 distribution from here it does not…
Anshul
  • 267
  • 1
  • 4
  • 13
16
votes
4 answers

Spring creating multiple instances of a singleton?

I have a graph of Spring beans which autowire each other. Heavily simplified illustration: ... public class Foo { @Autowired Bar bar; @Autowired Baz…
mindas
  • 26,463
  • 15
  • 97
  • 154
15
votes
3 answers

Correct way to get the instance of Application in android

Which of these ways is more proper for getting the instance of Application Initialise static field in Application.onCreate() and provide static access to it public class MyApplication extends Application { private static MyApplication…
Olegvarmy
  • 199
  • 1
  • 1
  • 8
15
votes
3 answers

PropertyPlaceholderConfigurer and environment variables in .properties files

I have a Spring application-context.xml with PropertyPlaceholderConfigurer to get properties' values from .properties file. Main and test source folders have separate .properties file. The issue is that I need to use environment variables in…
14
votes
2 answers

How to create TestContext for Spring Test?

I have a relatively small Java library that implements a few dozen beans (no database or GUI). I have created a Spring Bean configuration file that other Java projects use to inject my beans into their stuff. I am now for the first time trying to…
Dave
  • 21,524
  • 28
  • 141
  • 221
13
votes
5 answers

Best Practise of injecting applicationContext in Spring3

As in the title above, I am confused about pros cons between injecting applicationContext by directly @Autowired annnotation or implementing ApplicationContextAware interface in a singleton spring bean. Which one do you prefer in which cases and…
javatar
  • 4,542
  • 14
  • 50
  • 67
12
votes
2 answers

Does Spring Support JSON Configuration?

Does anyone know if Spring has any extensions that allow for configuring its ApplicationContext via JSON (or really any other format) rather than XML? I couldn't find anything in the official docs, but I was wondering if there were any other open…
donalbain
  • 1,158
  • 15
  • 31
11
votes
2 answers

What are advantages of using @ContextHierarchy over pure @ContextConfiguration

Hi I don't understand what advantages give me usage of @ContextHierarchy like below: @ContextHierarchy({ @ContextConfiguration("/test-db-setup-context.xml"), …
1
2
3
57 58