How to access Spring @Service object from jUnit test

前端 未结 2 402
无人及你
无人及你 2020-12-30 13:48

Situation: I have service implementation class annotated with @Service with access to properties file.

@Service(\"myService\")
public class          


        
2条回答
  •  情歌与酒
    2020-12-30 14:21

    Alternatively, to do an integration test I do this.

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations={"/applicationContext-test.xml"})
    @Transactional
    public class MyTest {
    
        @Resource(name="myService")
        public IMyService myService;
    

    Then use the service as you would normally. Add the app context to your test/resources directory

提交回复
热议问题