春天mvc 4没有加载的资源

时间:2015-07-17 21:03:36

标签: java spring spring-mvc

我正在使用gradle创建一个spring mvc项目。但是在构建之后,资源文件夹是空白的,因此所有js css文件都没有加载。我不确定是由于这种情况发生了什么。

webConfig:

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = { "com.decorpot.spring.config", "com.decorpot.spring.controller", "com.decorpot.*" })
public class WebConfig extends WebMvcConfigurerAdapter {

    @Bean
    public InternalResourceViewResolver jspViewResolver() {
        InternalResourceViewResolver bean = new InternalResourceViewResolver();
        bean.setPrefix("/WEB-INF/views/");
        bean.setSuffix(".jsp");
        return bean;
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/resources/**")
        .addResourceLocations("/resources/**")
        .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/views/**").addResourceLocations("/views/**");
    }
}

web.xml:

<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextClass</param-name>
        <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
    </init-param>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>com.decorpot.spring.config</param-value>
    </init-param>
</servlet>

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

还有什么我应该研究的。

0 个答案:

没有答案