Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8185577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:53:48+00:00 2026-06-07T01:53:48+00:00

Lets assume that I have sequencer and the following Beans. Sequencer is responsible for

  • 0

Lets assume that I have sequencer and the following Beans. Sequencer is responsible for taking the next value from a database sequence.
OracleSequencer is used in the production mode, TestSequencer during JUnit-Tests.

public interface Sequencer{
  long getNextValue();
}

@Named("OracleSequencer")
public class OracleSequencer implements Sequencer[
...
}

@Named("TestSequencer")
public class TestSequencer implements Sequencer[
...
}

And this is how I want to use it:

@Named
public class BusinessBean{
  @Inject
  private Sequencer sequencer;
}

My problem is:
When I run the app in the production mode I want to inject OracleSequencer in BusinessBean, when I run JUnit-Test I want to inject TestSequencer. Is it possible with JSR-330 (@Inject, @Named) ?

I found 2 dirty solutions:

  • at the begining of a test, Sequencer can be replaced in the bean, which is taken from Spring-ApplicationContext. It is possible when prototype is appropriate and TestSequencer doesnt have any other dependencies:

    BusinessBean bean = springContext.getBean(..);
    bean.setSequencer(new TestSequencer());

  • We can annotate OracleSequencer with @ProductionScope and TestSequencer with @TestScope and configure Spring that he scans appropiate annotations in the appropriate mode.

Do you have maybe any other idea how to solve this problem?

Spring 3.1.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T01:53:50+00:00Added an answer on June 7, 2026 at 1:53 am

    One solution would be to use Spring Profiles introduced with Spring 3.1, essentially define a profile named “prod” and “test”, let your OracleSequencer be created in prod profile and TestSequencer in test profile.

    For your test, activate the test profile alone, and your prod activate the prod profile.

    Here is one reference to Profiles – http://blog.springsource.com/2011/02/14/spring-3-1-m1-introducing-profile/

    Another solution like you suggested will be to override your sequencer bean in test with the TestSequencer, either by specifying a bean with the exact same name as your prod sequencer or specifying it in a new application context which is imported in test mode.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .jsp page that passes the variable from the servlet. Lets assume
Lets assume that I have the following configuration in my conf/InjectionConfig.groovy file: x {
Lets assume that we have PyV8: import PyV8 ctxt = PyV8.JSContext() and a python
I'm trying to create ProgressMonitor with changing totalWork. Lets assume that I have 2
Lets assume a scenario that i have a remote, a developer1 and a developer2.
Lets assume i have a bill number that has 12 numbers: 823 45678912 My
I have a city table that has two columns from_city to_city now lets assume
Lets assume that I have a computer which has a multicore processor and a
Hei, So lets assume that I have this ListBox.ItemTemplate: <phone:PhoneApplicationPage.Resources> <DataTemplate x:Key=DataTemplate1> <StackPanel Orientation=Horizontal>
I have created MDI application in Delphi. Lets assume that I have a bunch

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.