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

  • Home
  • SEARCH
  • 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 9245531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:17:14+00:00 2026-06-18T09:17:14+00:00

I have a requirement wherein I define a contract in Spring project and want

  • 0

I have a requirement wherein I define a contract in Spring project and want to autowire an external JAR during deploy that implements the contract (set of interfaces). I do not want to enforce the external JAR to be Spring-dependent so that it is as flexible as possible. Is it not possible in my Spring project to use the classes from external JAR as autowire substitutions wherever I am using my contract interfaces? Let me explain with an example:

Spring project:
@Controller
public class MyController {
     @Autowired
     private MyInterface interface;
}

Now the JAR implementing the contract interfaces may be provided by client and I may not know the package names before hand and it could even be a non-Spring project, so it may not be declared with @Component annotation.

e.g.

public class CustomerClass implements MyInterface {
}

Now in my spring project, is there a way to inject CustomerClass in place of MyInterface? I hope my question is clear.

Thanks

  • 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-18T09:17:15+00:00Added an answer on June 18, 2026 at 9:17 am

    @Paddy,
    Regarding to your concern about whether you can traditional XML way to achieve the same goal. The following is a sample code showing how to achieve it. Note: the interface MyInterface cannot be dynamic in this way, because the controller is holding a refernece to MyInterface .

    Spring application context config :

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
       <property name="locations" value="classpath:test.properties" />
    </bean>
    <bean id="myInterface" class="${myinterface.impl}"></bean>
    

    MyInterface and two different implementation class

    package au.net.test;
    
    public interface MyInterface {
    
        public String getMessage();
    }
    
    public class MyClass1 implements MyInterface{
    
        public String getMessage(){
            return "message from class 1";
        }
    }
    
    public class MyClass2 implements MyInterface{
    
        public String getMessage() {
            return "message from class 2";
        }   
    }
    

    test.properties file under classpath(you can use ant script and maven profile to change property value)

    myinterface.impl=au.net.test.MyClass2
    

    web layer Controller (you can inject the implementation class based on dynamic bean candidate)

    @Autowired
    private MyInterface myInterface;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a requirement wherein I want to detect two kind of events related
I have a requirement, wherein, the client want's an image to bounce, currently I'm
I have a requirement wherein I need to display on a User form, a
I have requirement, wherein I have to calculate totals for cash and credit cards
I have a requirement wherein fileA contains a list of rows with several columns,
I am new to extension development, I have a requirement wherein I need to
I have a requirement, wherein i need to show a wait message while an
We have a requirement, wherein the administrative user needs to proxy in as a
I have an Java/Java EE based application wherein I have a requirement to create
I am working on a requirement wherein I have to create a strong password.

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.