Issue
I have extended my class from RepositoryRestMvcConfiguration
according to href="https://docs.spring.io/autorepo/docs/spring-data-rest/2.2.0.M1/api/org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.html#configureRepositoryRestConfiguration(org.springframework.data.rest.core.config.RepositoryRestConfiguration)" rel="nofollow noreferrer">documentation it has configureRepositoryRestConfiguration
method which can be implemented but when I try to override this method I can't import it :|
Can anybody tell me Why this problem occurred?
EDIT : according to current version configureRepositoryRestConfiguration
method is not avialble.. so what method should I used instead of this?
Here is my code
MSARepositoryRestMvcConfiguration.java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
import org.springframework.security.data.repository.query.SecurityEvaluationContextExtension;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
@Configuration
public class MSARepositoryRestMvcConfiguration extends RepositoryRestMvcConfiguration {
private static final Logger LOG = LoggerFactory.getLogger(MSARepositoryRestMvcConfiguration.class);
@Value("${static.path}")
private String staticPath;
// @Bean
// public PasswordEncoder passwordEncoder() {
// return new BCryptPasswordEncoder();
// }
@Override
protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
config.setBasePath("/api");
// config.exposeIdsFor(User.class,Order.class,HeroRating.class,RiderLocation.class,OrderItem.class,Address.class,ShopDetail.class,PromoCode.class,RiderDuty.class,Criteria.class,Setting.class);
config.setReturnBodyForPutAndPost(true);
config.setReturnBodyOnCreate(true);
config.setReturnBodyOnUpdate(true);
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
super.addResourceHandlers(registry);
if(staticPath != null) {
LOG.info("Serving static content from " + staticPath);
registry.addResourceHandler("/photos/**").addResourceLocations("file:" + staticPath+"photos/");
registry.addResourceHandler("/").addResourceLocations("classpath:/static/");
}
}
@Bean
public SecurityEvaluationContextExtension securityEvaluationContextExtension() {
return new SecurityEvaluationContextExtension();
}
}
Error
It gives an error on configureRepositoryRestConfiguration
to remove override annotation
ErrorMessage
The method configureRepositoryRestConfiguration(RepositoryRestConfiguration) of type MSARepositoryRestMvcConfiguration must override or implement a supertype method
Solution
According to current version of spring document this method is not available so instead of `configureRepositoryRestConfiguration' we can override following method
@Configuration
public class MSARepositoryRestMvcConfiguration extends RepositoryRestMvcConfiguration {
@Override
public RepositoryRestConfiguration config() {
RepositoryRestConfiguration config = super.config();
config.setBasePath("/api");
config.exposeIdsFor(User.class);
return config;
}
}
Answered By - SFAH
Answer Checked By - Marie Seifert (JavaFixing Admin)