Config.java 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package cn.efunbox.audio.config;
  2. import cn.efunbox.audio.aop.AdminInterceptor;
  3. import cn.efunbox.audio.aop.AuthInterceptor;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.context.EnvironmentAware;
  6. import org.springframework.context.annotation.Bean;
  7. import org.springframework.context.annotation.ComponentScan;
  8. import org.springframework.context.annotation.Configuration;
  9. import org.springframework.core.env.Environment;
  10. import org.springframework.web.cors.CorsConfiguration;
  11. import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
  12. import org.springframework.web.filter.CorsFilter;
  13. import org.springframework.web.servlet.config.annotation.EnableWebMvc;
  14. import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
  15. import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
  16. /**
  17. * 用户权限验证拦截器
  18. * Created by yao on 17-9-29.
  19. */
  20. @Configuration
  21. @EnableWebMvc
  22. public class Config extends WebMvcConfigurerAdapter{
  23. /**
  24. * 直接采用new interceptor或Autowired注入拦截器会导致dao为null的错误
  25. * @return
  26. */
  27. @Bean
  28. AuthInterceptor authInterceptor(){
  29. return new AuthInterceptor();
  30. }
  31. @Bean
  32. AdminInterceptor adminInterceptor(){
  33. return new AdminInterceptor();
  34. }
  35. @Override
  36. public void addInterceptors(InterceptorRegistry registry) {
  37. registry.addInterceptor(authInterceptor())
  38. .addPathPatterns("/audio/search");
  39. registry.addInterceptor(adminInterceptor())
  40. .addPathPatterns("/**")
  41. .excludePathPatterns("/device/**", "/admin/**", "/audio/search");
  42. }
  43. }