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")
@CrossOrigin
public interface AmazonProductRepository extends PagingAndSortingRepository<AmazonProduct, Long> {
class CustomRestMvcConfiguration extends RepositoryRestMvcConfiguration {
@Override
@Bean
public HateoasPageableHandlerMethodArgumentResolver pageableResolver() {
HateoasPageableHandlerMethodArgumentResolver resolver = super.pageableResolver();
resolver.setOneIndexedParameters(true);
return resolver;
}
}
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.