springboot访问windows本地和linux上的外部文件

springboot如何访问windows本地和linux上的外部文件?
首先编写一个WebMvcConfiguration配置文件类
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

@Value("${jarPath}")     //file:/root/gspackage/
private String path;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/**").addResourceLocations(path);

配置文件中新增静态映射,需要先把springboot默认的映射加上,用file来进行指定想要访问的静态目录
linux服务器上以"/"表示跟目录,windows可以用file: d: 来进行映射

配置方式参考如下:

spring:
static-path-pattern: /**
resources:
static-locations: classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,classpath:/itstyle/, file:/

springsecurity的一些记录
@EnableWebSecurity
@Configuration
public class SercurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
UserDetailsServiceImpl userDetailsService;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    super.configure(auth);
    //密码编码器
    BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
    InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
    User user = new User();
    user.setId(1);
    user.setName("xiaoming");
    user.setPassword("123456");
    user.setRole("USER");
    manager.createUser(user);
    //使用内存存储
    auth.inMemoryAuthentication()
            //设置密码编码器
            .passwordEncoder(passwordEncoder)
            //注册用户admin,密码为abc,并赋予USER和ADMIN的角色权限
            .withUser("admin")
            //可通过passwordEncoder.encode("abc")得到加密后的密钥
            .password("11111111111111")
            //赋予角色ROLE_USER和ROLE_ADMIN
            .roles("USER", "ADMIN")
            //连接方法and
            .and()
            //注册用户myuser,密码为123456,并赋予USER的角色权限
            .withUser("myuser")
            //可通过passwordEncoder.encode("123456")得到加密后的密钥
            .password("333333333333333333")
            //赋予角色ROLE_USER
            .roles("USER");
    //2种方式可以处理权限认证的过程
    auth.userDetailsService(userDetailsService).passwordEncoder(new BCryptPasswordEncoder());
@Override
public void configure(WebSecurity web) throws Exception {
    super.configure(web);
    FilterSecurityInterceptor interceptor = new FilterSecurityInterceptor();
    //获取到拦截器,来处理一些拦截信息
    web.securityInterceptor(interceptor);
@Override
protected void configure(HttpSecurity http) throws Exception {
    super.configure(http);
    //需要spring security保护的断点
    String[] endpoints = {
            "auditevents", "beans", "conditions", "configprops", "env", "flyway", "httptrace",
            "loggers", "liquibase", "metrics", "mappings", "scheduledtasks", "sessions", "shutdown", "threaddump"
    //定义需要验证的端点
    http.requestMatcher(EndpointRequest.to(endpoints))
            //签名登录后
            .authorizeRequests().anyRequest()
            //要求登录用户拥有ADMIN角色
            .hasRole("ADMIN")
            .and()
            //请求关闭页面需要ROLE_ADMIN角色
            .antMatcher("close").authorizeRequests().anyRequest().hasRole("ADMIN")
            .and()
            //启动http基础验证
            .httpBasic();
    //处理对http请求的拦截认证
    http.authorizeRequests()
            .antMatchers("/test").permitAll()
            .antMatchers("/login").permitAll()
            .antMatchers("/look").hasRole("user")
            .antMatchers("/**").fullyAuthenticated()
            .and()
            .formLogin().loginPage("/login")
            .failureForwardUrl("/error")
            .successForwardUrl("/index");

@Component
public class UserDetailsServiceImpl implements UserDetailsService {
@Override
public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
return new UserDetails() {
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
CopyOnWriteArrayList<GrantedAuthority> authorities = new CopyOnWriteArrayList<>();
SimpleGrantedAuthority authority = new SimpleGrantedAuthority("user");
authorities.add(authority);
return authorities;

        @Override
        public String getPassword() {
            return "123456";
        @Override
        public String getUsername() {
            return "xiaoming";
        @Override
        public boolean isAccountNonExpired() {
            return false;
        @Override
        public boolean isAccountNonLocked() {
            return false;
        @Override
        public boolean isCredentialsNonExpired() {
            return false;
        @Override
        public boolean isEnabled() {
            return false;

public class User implements UserDetails {

private String name;
private String password;
private int id;
private String role;
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
    return null;
@Override
public String getPassword() {
    return null;
@Override
public String getUsername() {
    return null;
@Override
public boolean isAccountNonExpired() {
    return false;
@Override
public boolean isAccountNonLocked() {
    return false;
@Override
public boolean isCredentialsNonExpired() {
    return false;
@Override
public boolean isEnabled() {
    return false;
public String getName() {
    return name;
public void setName(String name) {
    this.name = name;
public void setPassword(String password) {
    this.password = password;
public int getId() {
    return id;
public void setId(int id) {
    this.id = id;
public String getRole() {
    return role;