'405 Method not allowed despite exposing all methods when using RepositoryRestConfiguration.disableDefaultExposure()

I don't want to expose my repositories by default and it looks like RepositoryRestConfiguration.disableDefaultExposure() does exactly what I want; however I get a 405 response when calling /{respository/{id}.

I have marked all of the methods on my repository as exposed and as far as I can tell all other methods are working with the exception of FindById.

@RepositoryRestResource(exported = true)
interface MyEntityRepository : PagingAndSortingRepository<MyEntity, Int> {

    @RestResource(exported = true)
    override fun findAll(sort: Sort): MutableIterable<MyEntity>

    @RestResource(exported = true)
    override fun findAll(pageable: Pageable): Page<MyEntity>

    @RestResource(exported = true)
    override fun <S : MyEntity?> save(entity: S): S

    @RestResource(exported = true)
    override fun findAll(): MutableIterable<MyEntity>

    @RestResource(exported = true)
    override fun deleteById(id: Int)

    @RestResource(exported = true)
    override fun deleteAll(entities: MutableIterable<MyEntity>)

    @RestResource(exported = true)
    override fun deleteAll()

    @RestResource(exported = true)
    override fun <S : MyEntity?> saveAll(entities: MutableIterable<S>): MutableIterable<S>

    @RestResource(exported = true)
    override fun count(): Long

    @RestResource(exported = true)
    override fun findAllById(ids: MutableIterable<Int>): MutableIterable<MyEntity>

    @RestResource(exported = true)
    override fun delete(entity: MyEntity) 

    @RestResource(exported = true)
    override fun existsById(id: Int): Boolean

    @RestResource(exported = true)
    override fun findById(id: Int): Optional<MyEntity>

}

@Component
class SpringDataRestCustomization() : RepositoryRestConfigurerAdapter() {

    override fun configureRepositoryRestConfiguration(config: RepositoryRestConfiguration?) {
        config!!.disableDefaultExposure()
    }
}

Results in:

GET /myentities/1
cache-control: no-cache
postman-token: 3d310c2e-2e1c-4587-880d-cc2f79cbb9eb
user-agent: PostmanRuntime/7.2.0
accept: */*
host: localhost:8080
accept-encoding: gzip, deflate

HTTP/1.1 405
status: 405
allow: PUT,PATCH,DELETE,OPTIONS
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
cache-control: no-cache, no-store, max-age=0, must-revalidate
pragma: no-cache
expires: 0
x-frame-options: DENY
content-length: 0
date: Fri, 27 Jul 2018 11:42:25 GMT

Using Spring Boot with spring-data-releasetrain.version set to Kay-SR9.

Is there a method I've missed or something else I need to do to allow GETs? I don't have a controller for this (or any) repositories.

--- Edit ---

After doing some poking I think I've found the reason for this but I don't really like my solution; when Spring is looking for the findById method it's looking for a parameter of type java.lang.Integer but my method is defined as primitive int; Kotlin is setting the ID type argument to java.lang.Integer but the function argument to int so they don't match up.

Updating my repository class as below works but causes Warning:(13, 67) Kotlin: This class shouldn't be used in Kotlin. Use kotlin.Int instead.:

@RepositoryRestResource(exported = true)
interface MyEntityRepository : PagingAndSortingRepository<MyEntity, java.lang.Integer> {

    ...

    @RestResource(exported = true)
    override fun findById(id: java.lang.Integer): Optional<MyEntity>

}

--- Edit 2 ---

I'm currently using the code below which works; however Kotlin doesn't think my method overrides the inherited one (if I add the overrides keyword back in it won't compile).

@RepositoryRestResource(exported = true)
interface MyEntityRepository : PagingAndSortingRepository<MyEntity, Int?> {

    ...

    @RestResource(exported = true)
    fun findById(id: Int?): Optional<MyEntity>

}


Solution 1:[1]

The edit from @jebbench solved the issue for GET /{entity}/{id}. Additionally I had to do this for delete:

    @RestResource(exported = true)
    fun deleteById(id: Int?): Optional<MyEntity>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Zack