Home Can't import `configureRepositoryRestConfiguration` in Spring
Reply: 2

Can't import `configureRepositoryRestConfiguration` in Spring

Firza Ahmed
1#
Firza Ahmed Published in 2018-01-12 08:54:55Z

I have extended my class from RepositoryRestMvcConfiguration according to 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
Marc Tarin
2#
Marc Tarin Reply to 2018-01-12 10:53:38Z

From the current reference documentation, Configuring Spring Data REST:

To customize the configuration, register a RepositoryRestConfigurer (or extend RepositoryRestConfigurerAdapter) and implement or override the configureā€¦-methods relevant to your use case.

SDR configuration outside of RepositoryRestMvcConfiguration was addressed in DATAREST-621 and RepositoryRestConfigurer was introduced in this commit.

Firza Ahmed
3#
Firza Ahmed Reply to 2018-01-12 11:23:19Z

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; 
        }
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.306821 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO