New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GET on RestRepository not possible, if a RestController for the same path is available [DATAREST-522] #896
Comments
Oliver Drotbohm commented Try two things: re-add |
Felix Huch commented First, thanks for this fast and great support! We have tried these two ways and the result is the same.
A |
Oliver Drotbohm commented Hm, weird. Do you have a tiny sample I can look at? |
Felix Huch commented I added a minimal sample project to this ticket. The resources are available under /api/* |
Oliver Drotbohm commented Adding the following test case works for me: @RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(classes = AppConfig.class)
public class AppTest {
@Autowired WebApplicationContext context;
MockMvc mvc;
@Before
public void setUp() {
this.mvc = MockMvcBuilders.webAppContextSetup(context).build();
}
@Test
public void testname() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/person/1").accept(MediaType.APPLICATION_JSON)).andExpect(
MockMvcResultMatchers.status().isOk());
}
} When providing samples, please make sure there's something to execute, that clearly shows what you're expecting and what's wrong. I'm not gonna deploy anything anywhere. Ideally a |
Oliver Drotbohm commented Nevermind, I see, you'd like to override |
Felix Huch commented Thanks! I will keep that in mind ;-) |
Thibaud Lepretre commented Before Fowler train, I achieve your needs like following: http://stackoverflow.com/questions/27712038/spring-data-rest-and-collections-with-unique-constraints/27802520#27802520. Since Fowler train I had the same needs as you that why I recreate the handlerMapping chain with delegation to avoid My SO answer can be "patch" solution for you or help investigation. I really hope that Spring Data Rest provides such feature in futur! |
Oliver Drotbohm commented The issue was us not handling exceptions other |
Felix Huch commented Unfortunately its not working. We added <repositories>
<repository>
<id>spring-libs-snapshot</id>
<url>https://repo.spring.io/libs-snapshot</url>
</repository>
</repositories> and <spring.data.rest.version>2.3.1.BUILD-SNAPSHOT</spring.data.rest.version> to our pom.xml. The tests look like
@Test
public void checkGET() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/person")
.accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk());
}
@Test
public void checkPOST() throws Exception {
mvc.perform(MockMvcRequestBuilders.post("/person")
.accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk());
} and we get
The |
Oliver Drotbohm commented When I run your sample application's test case It might make sense to rather create a repo that you update than referring to an attachment here that I have to modify by some means, as the latter is just begging for inconsistencies in what you use and what I am trying to reproduce here |
Felix Huch commented I'm sorry for the circumstances. I created a github-repo: https://github.com/felixhuch/spring-data-rest-playground |
Oliver Drotbohm commented As indicated in my very first comment you need to switch to |
Felix Huch commented Jap :-) Thank you very much! |
Robert Rackl commented Just in case some else also stumbles over this: "No @RepositoryRestController
@RequestMapping("person") // only set the path mapping here!
public class PersonController{
@RequestMapping(method = RequestMethod.POST) // no value for path here!
public @ResponseBody PersistentEntityResource savePerson(@RequestBody Person person, PersistentEntityResourceAssembler resourceAssembler)) {
...
} |
Robert Rackl commented Actually ... this still doesn't work. I'll open a new ticket |
Felix Huch opened DATAREST-522 and commented
We have a Spring Data REST project, with several
@RepositoryRestResource
annotated Spring Data Repositories.Example:
We want to override the
POST
/PATCH
method of one of these repositories. So we annotate a RestController with@RestController
and the annotation@RequestMapping
has the same path as the repository.Example:
The
POST
/PATCH
works fine. But now aGET
to/person
(to receive all Persons) throws anHttpRequestMethodNotSupportedException
and says: Request method 'GET' not supported.A
GET
to/person/1
instead is working just fine.We had a look at https://jira.spring.io/browse/DATAREST-490 and the
@BasePathAwareController
, but this doesnt seem to change anythingAffects: 2.3 GA (Fowler)
Attachments:
Issue Links:
Backported to: 2.3.1 (Fowler SR1)
0 votes, 5 watchers
The text was updated successfully, but these errors were encountered: