2014-02-06 2 views
1

엔터프라이즈 응용 프로그램을 스프링으로 변환해야합니다. 지금까지 모든 것이 작동하고 있습니다. 하지만 여전히 2 개의 콩에서 @Startup 주석을 대체해야합니다.@Startup에 해당하는 스프링이 있습니까?

봄철 이에 상응하는 의견이 있습니까, 아니면 봄에 어떻게합니까?

미리 감사드립니다.

+0

'SmartLifeCycle'? –

+0

당신은 그것이 무엇을 설명 할 수 있습니까? – chrylis

+0

@RC. 설명 할 수 있니? –

답변

3

당신이 요구하는 것이 맞는지 확실하지 않습니다. 행동 실험

@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() { 

    } 
} 

당신이 단위 테스트를 작성하는 방법의 예를 추가 : 난 항상 응용 프로그램의 시작시 수행해야 할 물건을 할, 내 봄 콩에 @PostConstruct 어노테이션을 사용하여 Spring 컨텍스트에서 빈의

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. 
    } 
} 
+0

나는 @PostConstruct aswel을 가지고 있으며 같은 것을 생각하고 있었다. '@Startup'은 봄에 필요하지 않을 수도 있습니다. 왜냐하면 콩은 이미 시작할 때 초기화되기 때문입니다. 비록 내가 확신하는 약간의 확인을 사랑할 것이지만. –

+0

예, 작동하는지 확인할 수 있습니다. 물론 bean을 처음부터 초기화하는 스프링 컨텍스트를 정의해야합니다. 단위 테스트를 작성하는 방법과 관련하여 내가 추가 한 예제를 검토하여 문제를 확인하십시오. – aksamit

+0

고마워요! 그럼 내가 끝났어. –

관련 문제