user5500750 user5500750 - 3 years ago 183
reST (reStructuredText) Question

Java SpringMVC where to place the RepositoryRestMvcConfiguration (@Configuration) file

I have come across so many tutorials about configuration files for java SpringMVC projects and usually have the @Configuration at their class name but they never mention where exactly to place these files.

For example I have learnt that I might be able to change Spring Data Rest rest api by extending the RepositoryRestMvcConfiguration.

1) I want to be able to be able to have longer urls for the repositories so instead of having api/amazonproducts I could have api/amazon/products. Apparently this is impossible. I end up having;

@RepositoryRestResource(collectionResourceRel = "amazonproducts", path = "amazonproducts")
public interface AmazonProductRepository extends PagingAndSortingRepository<AmazonProduct, Long> {

All I have to do is for example create class like;

class CustomRestMvcConfiguration extends RepositoryRestMvcConfiguration {

public HateoasPageableHandlerMethodArgumentResolver pageableResolver() {

HateoasPageableHandlerMethodArgumentResolver resolver = super.pageableResolver();
return resolver;

I don't know in which file/folder to place this code. I am using Eclipse Java EE Oxygen. I have created a maven project and I am currently testing it on spring-boot

Answer Source

You can place @Configuration annotated classes in any package you want, as long as the package is included in the component scanning.

In Spring Boot, that by default means in the same package as the class with @SpringBootApplication, or any subpackage thereof, same as for all other classes managed by Spring.

Other than that, Spring doesn't care about package names.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download