문제

Hi i have an web application unsing spring and hibernate. I'm looking for a possiblity to call some startup functions which are executed when running tests, too.

I uste the AbstractTransactionalJUnit4SpringContextTests class and tried the following interfaces

  • ApplicationListener
  • Lifecycle
  • ServletContextListener

but none of them is called under junit.

Any tips (hibernate-database-acces should be available at this time)?

도움이 되었습니까?

해결책 2

My solution: ApplicationContextAware, just add a class to your classpath:

public class SpringApplicationContext implements ApplicationContextAware {

    private static ApplicationContext CONTEXT;

    public void setApplicationContext(ApplicationContext context) throws BeansException {
        CONTEXT = context;
        // DO DB INIT STUFF
    }

다른 팁

You can use the Annotation ContextConfiguration to load the application Context for your Tests.

@ContextConfiguration(locations="test/test-context.xml")
public class MyTestsClass {
    // class body...
}

Regards Michael

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top