在类级别添加@REQUESTMAPPING注释后无法加载CSS和JS文件

时间:2016-09-26 09:52:22

标签: javascript css spring-mvc

我在类级别为一些视图(jsp)添加了@RequestMapping注释。当我尝试使用正确的URL映射访问这些页面时,页面显示但无法正确呈现,并且无法加载.js和.css文件。在浏览器中我得到了以下错误。  GET 404(未找到) 在服务器日志中我得到以下消息。 org.springframework.web.servlet.PageNotFound noHandlerFound 警告:在具有名称' spring-dispatcher'的DispatcherServlet中,没有找到带有URI [/ccb/invoice/webjars/adminlte/2.3.3/plugins/iCheck/icheck.min.js]的HTTP请求的映射。 虽然在Servlet配置文件中的静态资源映射完全正常,并且在那些在类级别没有@requstmapping注释的页面上加载它,但不确定为什么会出现问题。

你可以告诉我在哪里弄错了。

@Controller @RequestMapping("/invoice") @SessionAttributes("ListOrderItems") public class InvoiceController {
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public ModelAndView adminPage() {
        System.out.println("Im in /Index** Mapping");
        String username;
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        username = auth.getName(); //get logged in username
        username.toUpperCase();
        // Logic to build menue based on the Role of the user.
        HashMap hm = new HashMap();
        OrderItems od = new OrderItems();
        ModelAndView model = new ModelAndView();
        model.addObject("usr", username);
        //Set the object for Menue Links on the Page
        model.addObject("mnue", hm);
        model.setViewName("index");
        model.addObject("odi",od);
        return model;

    } }


Dispatcher Servlet configuration file: <mvc:resources mapping="/webjars/**" location="/webjars/" />
    <mvc:resources mapping="/resources/**" location="/resources/" />
    <mvc:annotation-driven/>
    <bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"
>
        <property name="prefix">
            <value>/WEB-INF/jsp/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

1 个答案:

答案 0 :(得分:0)

尝试在调度程序servlet中添加xmlns

xmlns="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
     http://www.springframework.org/schema/mvc/spring-mvc.xsd

然后

<resources mapping="/resources/**" location="/resources/" />
    <beans:bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>