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 8084675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:52:04+00:00 2026-06-05T17:52:04+00:00

I have two spring beans as follows: @Component(A) @Scope(prototype) public class A extends TimerTask

  • 0

I have two spring beans as follows:

@Component("A")
@Scope("prototype")
public class A extends TimerTask {

    @Autowired
    private CampaignDao campaignDao;
    @Autowired
    private CampaignManager campManger;
    A(){
        init_A();
       }
    }

I have to make a new object of A with new keyword, due to a legacy code

@Component("B")
@Scope("prototype")
public class B{
     public void test(){
       A a = new A();
     }
}

when Running -> the spring beans in the class A are null, can i create a new instance of the spring bean A and still use autowiring in it ?

  • 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-05T17:52:06+00:00Added an answer on June 5, 2026 at 5:52 pm

    Yours component “A” is not created by Spring container, thus, dependencies are not injected. However, if you need to support some legacy code (as I understand from your question), you can use @Configurable annotation and build/compile time weaving:

    @Configurable(autowire = Autowire.BY_TYPE)
    public class A extends TimerTask {
      // (...)
    }
    

    Then, Spring will inject autowired dependencies to component A, no matter if it’s instantiated by container itself, or if it’s instantiated in some legacy code by new.

    For example, to set up build-time weaving with maven plugin you have to:

    1. Add <context:spring-configured/> to the Spring application context
    2. Configure Maven AspectJ plugin:

    in the build plugins section:

    <build>
      <plugins>
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>aspectj-maven-plugin</artifactId>
          <version>1.4</version>
          <configuration>
            <complianceLevel>1.6</complianceLevel>
            <encoding>UTF-8</encoding>
            <aspectLibraries>
              <aspectLibrary>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aspects</artifactId>
              </aspectLibrary>
            </aspectLibraries>
            <!-- 
              Xlint set to warning alleviate some issues, such as SPR-6819. 
              Please consider it as optional.
              https://jira.springsource.org/browse/SPR-6819
            -->
            <Xlint>warning</Xlint>
          </configuration>
          <executions>
            <execution>
              <goals>
                <goal>compile</goal>
                <goal>test-compile</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </build>
    

    …and the dependencies section:

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aspects</artifactId>
      <version>3.1.1.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjrt</artifactId>
      <version>1.6.11</version>
    </dependency>
    

    Please consult Spring reference for more details:
    http://static.springsource.org/spring/docs/current/spring-framework-reference/html/aop.html#aop-atconfigurable

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

Sidebar

Related Questions

Given I have a Spring bean configured as @Service(myService) public class DefaultService extends MyService
For example i have two beans: class Bean1 { private SomeService service1; private SomeService
i am using spring 3, and i have two beans of view scope: 1-
If I have a Spring Controller with two SEPARATE methods, one annotated by: @ExceptionHandler(Exception.class)
I have a wicket page , which contains two Spring-managed beans , one is
Consider the following Spring Service class. The spring scope defined is Singleton. The two
i have a problem with spring autowire feature which found two beans with the
i am using PrettyFaces 3.3.0 with Spring Security 3 i have two beans UserBean
I have two beans, beanA and beanB , in my Spring config. Both of
I have two projects and each project has Spring XML files in their respective

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.