Is there a spring equivalent to @Startup?

java, quartz-scheduler, tomcat

Solution

Not sure if this is what you are asking for. I always use the @PostConstruct annotation in my Spring-beans, to do stuff that needs to be done at startup of the application:

@Component
public class SchedulerBootstrap {

    @Autowired
    MyRepository myRepository;

    @Autowired
    OpenPropertyPlaceholderConfigurer configurer;

    @PostConstruct
    /**
     * This method will be called after the bean has been 
     * instantiated and all dependencies injected.
     */
    public void init() {

    }
}

Adding an example of how you can write a unit test to experiment with the behaviour of the bean in a Spring context.

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;

@ContextConfiguration(locations = {"classpath:spring-context.xml"})
public class BootstrapTest extends AbstractJUnit4SpringContextTests {

    @Autowired
    SchedulerBootstrap schedulerBootstrap;

    @Test
    public void myTest() { 
        //Some code that berifies that init-method had been called.
        //Or start unit test in debug-mode and add a breakpoint in the 
        //init-method, you will see it being called before the test is executed.
    }
}

Problem

I have to convert an enterprise application to spring. I've got everything working so far. But I still need to replace the @Startup annotation on 2 of my beans. Is there a spring equivalent or how would you do this in spring? Thanks in advance!

Original source