In my webapplication there are two datasource beans in the applicationContext one is to be used for real-env and one is to be used for execution of test. The dataSource objects is injected in one DAO class. Using Spring profile how can I configure test dataSource should be injected in the DAO while running Test (JUnit) and real-env dataSource should be injected in the DAO while code deployed to real-env ?
Injecting specific bean to DAO using Spring profile
1k Views Asked by SyParth At
1
There are 1 best solutions below
Related Questions in SPRING
- Redirect inside java interceptor
- Spring RestTemplate passing the type of the response
- spring-integration-dsl-groovy-http return null when i use httpGet method
- Custom Spring annotation for request parameters
- Spring - configure Jboss Intros for xml with java config?
- HTTP Status 404 - Not Found in Spring 3.2.7
- AndroidAnnotations how to use setBearerAuth
- android I/O error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found
- Show login dialog when not authenticated yet
- Spring Data Rest supporting json and xml
- @Value annotation not resolved in a class that belongs to dependency jar
- Remove nested _embedded fields while using projections
- How to send Rest GET request that contains "#" value in url parameters?
- How to inject spring bean into Validator(hibernate)
- How to keep a variable in the URL when using Spring LocaleChangeInterceptor
Related Questions in DEPENDENCY-INJECTION
- Resolve object using DI container with object instance
- Angularjs dependency injection parameter
- Dagger 2 - unable to inject object
- How to have SimpleInjector resolve viewmodel dependencies?
- Command Bus/Dispatcher and Handler registration without Dependency Injection
- Receiving a NoClassDefFoundError even though jar is successfully downloaded via Maven and referenced in pom.xml
- automapper error collection was modified when multiple users are creating a user
- When to use DI over abstract inheritance?
- Simple Injector Dependency Resolution Error - Could not load file or assembly System.Web.Http
- How can I use Dependency Injection to either Override a method or to set a default method when no dependency is explicitly injected?
- Injecting login session using Dagger
- What's wrong with this factory dependencies issue?
- JAVA CDI: sometimes injection stays null when injected into EJB and interceptor in request scope
- Why a service of main module available in other modules?
- Can I specify multiple parameters using WhenInjectedInto for ninject?
Related Questions in JUNIT4
- Some of my tests show prepended with junit.framework
- Can not convert from Class<PowerMockRunner> to Class<? extends Runner>
- Java JUnit4: Make simple assertEquals Test pass
- Library throws AssertionError making my tests fail
- Don't let test stop on failure
- using command line how run junit test present inside the war file
- hibernate rollback not working in service layer
- How to test Exceptions with ActivityTestCase or InstrumentationTestCase
- Unit Testing GMavenPlus Groovy Mojos - project.basedir not being expanded
- initializationError while executing Robolectric JUnit 4 test case
- junit 4 all pairwise permutations of test methods
- Ant JUnit Error No runnable method. initializationError
- ContextNotActiveException: WELD-001303: No active contexts for scope type org.apache.deltaspike.core.api.scope.GroupedConversationScoped
- Objects behave weird when mocking private method of class under test using jmockit
- Load balance execution of UI tests (Selenium) on multiple identical app instances (URLs)
Related Questions in SPRING-PROFILES
- Enabling/disabling a web.xml filter using a Spring profile
- Default Spring bean when profile is not present
- Error creating Spring Profiles
- How does Spring properties look up/precedence work?
- spring.profiles.active not honoured
- Springboot - multiple property files per profile
- Spring: How to do AND in Profiles?
- How to set a Spring profile to a package?
- What happens in Spring if I use the @ActiveProfiles annotation on a configuration class instead use it on the class that defines my beans?
- Is there profiles in Apache Aries Blueprint like Spring Profiles?
- Loading util:properties with Spring Profile causes multiple occurrences of ID
- what does this @Profile("!json") mean
- Using Spring @ActiveProfile in integration tests
- Spring Properties files configuration and maven integration in different env
- Profiles In dagger
Related Questions in SPRINGJUNIT4CLASSRUNNER
- Using multiple runner annotation in test class for spring-boot and testrail
- SpringJunit4Runner no tests found
- maven does not detect tests from the command line
- How to write junit for RabbitListenerEndpointRegistry in spring framework
- initializationError running junit test with SpringJUnit4ClassRunner after moving or deleting a class
- unable to mock RestTemplate response
- why can't I access ApplicationContext from ApplicationContextAware implemented bean
- springboottest how to prevent running application
- Unit testing with SpringJUnit4ClassRunner using only @Component and @Autowired
- Start JUnit test with fresh Spring Context
- spring contextconfiguration using bean several times
- when to create objects using new operator or use auto-wire when testing a class?
- The import org.springframework.test.context.junit4.SpringJUnit4ClassRunner cannot be resolved
- Could not open JDBC Connection for transaction in Spring Junits
- JmsListenerContainerFacotory Not available: NoSuchBeanDefinitionException, even though have configured a DefaultJmsListenerContainerFactory
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Actually there are two ways to achieve your target:
To be used for real env:
To be used for tests :
In your web.xml specify default-spring-config.xml as the contextConfigLocation to be used by spring in runtime :
And finally specify test-spring-config.xml in ContextConfiguration for Test :
First of all add those lines to your web.xml to let Spring be aware of the default profile (real-env):
Now into your Spring config file (one single config file) create two different datasources :
Then inject DataSource into your test classes using ActiveProfiles:
Source : https://spring.io/blog/2011/06/21/spring-3-1-m2-testing-with-configuration-classes-and-profiles