2014-09-10 29 views
1

我的问题与访问资源有关。更具体地说,我的所有JSP都无法访问JS和CSS(资源)。对于基于Java的配置,此XML标记<mvc:resources mapping="/resources/**" location="/WEB-INF/resources/"/>是否有任何模拟?基于Java的配置是否有任何类似的XML资源映射?

我的配置类

@EnableWebMvc 
@Configuration 
@ComponentScan("com.springapp.mvc") 
@PropertySource("classpath:names.properties") 
public class WebMvcConfig extends WebMvcConfigurerAdapter { 

    @Bean 
    public InternalResourceViewResolver setupViewResolver() { 
     InternalResourceViewResolver resolver = new InternalResourceViewResolver(); 
     resolver.setPrefix("/WEB-INF/pages/"); 
     resolver.setSuffix(".jsp"); 
     return resolver; 
    } 

    // other beans 
} 

回答

1

成立!我只需要将此方法添加到我的配置类中。

@Override 
public void addResourceHandlers(ResourceHandlerRegistry registry) { 
    registry.addResourceHandler("/resources/**").addResourceLocations("/WEB-INF/resources/"); 
} 
相关问题