Мы считаем, что Spring Rest Doc
отлично подходит для документирования остальных API. Но он основан на Spring MVC Test
, и мы не можем понять, как использовать Spring MVC Test
в моих приложениях Grails (Grails 3.0.5).
Я попытался использовать класс конфигурации (с @Configuration
и @ComponentScan
) для сканирования компонентов Grails в тестовом контексте, но, похоже, ничего не было загружено (при выполнении http-запроса к mockmvc
он получил 404).
Я также попытался настроить контроллер Grails напрямую и получил ошибку времени выполнения.
Не удалось автоподключить поле: частный Reactor.bus.EventBus
Я также пытался добавить @Integration
(из Grails) в тестовый класс, но получил ту же ошибку.
Пожалуйста помоги.
Вот несколько примеров кода. я пытался добавить класс конфигурации или расположение классов или контроллер Grails в ContextConfiguration тестового класса ниже. И сам тестовый класс в основном следует ссылке spring rest doc
.
import org.junit.Before;
import org.junit.Rule;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.restdocs.RestDocumentation;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration
//TODO how to scan Grails components into the test context
public class QuestionRestSpec {
@Rule
public final RestDocumentation restDocumentation = new RestDocumentation("build/generated-snippets");
@Autowired
private WebApplicationContext context;
private MockMvc mockMvc;
@Before
public void setUp() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(context)
.apply(documentationConfiguration(this.restDocumentation))
.build();
}
}
Класс конфигурации (который бесполезен):
@Configuration
@EnableWebMvc
@ComponentScan
public class AskConfig {
}
@Integration
и я бы попробовал ввестиApplicationContext
с помощью@Autowired
. Можете ли вы поделиться своей попыткой сделать то, что не сработало? - person Andy Wilkinson   schedule 22.10.2015spring rest doc
. - person bitmountain   schedule 23.10.2015