How to write JUnit test with Spring Autowire?

前端 未结 6 486
孤城傲影
孤城傲影 2020-12-03 06:45

Here are the files that I use:

component.xml




        
6条回答
  •  情歌与酒
    2020-12-03 07:12

    I've done it with two annotations for test class: @RunWith(SpringRunner.class) and @SpringBootTest. Example:

    @RunWith(SpringRunner.class )
    @SpringBootTest
    public class ProtocolTransactionServiceTest {
    
        @Autowired
        private ProtocolTransactionService protocolTransactionService;
    }
    

    @SpringBootTest loads the whole context, which was OK in my case.

提交回复
热议问题