Spring Security无法加载资源:服务器响应状态为404

时间:2016-02-29 10:11:44

标签: java html5 spring spring-security

当我导航到经过身份验证的网址时,所有静态内容甚至网址href中的url都附加了路由的网址,因为我获得了该网页中所有资源的404以及href元素内的所有网址< / p>

for e.x

    <security:http auto-config="true" use-expressions="false"> 
            <security:intercept-url pattern="/reports/**" access="ROLE_USER"/>
            <security:intercept-url pattern="/**" access="ROLE_ANONYMOUS"/>

            <security:form-login login-page="/login.do" login-processing-url="/login.do" username-parameter="custom_username" 
                password-parameter="custom_password"
                 authentication-success-handler-ref="authSuccessHandler"
                default-target-url="/"
                always-use-default-target="true"
                authentication-failure-url="/login.do?error=true"/>
                <security:logout logout-url="/logout.do" logout-success-url="/login.do?logout=true"/>
            <security:csrf disabled="true"/>
        </security:http >

        <security:authentication-manager>
            <security:authentication-provider>
                <security:user-service>
                    <security:user name="user1" password="password" authorities="ROLE_USER"/>
                    <security:user name="admin" password="password" authorities="ROLE_USER,ROLE_FOO"/>
                </security:user-service>
            </security:authentication-provider>
        </security:authentication-manager>
<security:http  pattern="**/styles/**"  security="none" />
<security:http  pattern="**/js/**"  security="none" />

当我导航到 myapp / reports / 时,我的静态内容已更改为

enter image description here

通常在html中看起来像

<link href="styles/jqueryUI.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="styles/Home.css">
<link rel="stylesheet" href="styles/metisMenu.min.css">
<link rel="stylesheet" href="styles/sideBar.css">

我错过了一些东西,即使我已经使用了mvc:resources

<mvc:annotation-driven/>
<mvc:resources mapping="/WebContent/styles/**" location="css/"  />
<mvc:resources mapping="/WebContent/js/**" location="js/"  />
<mvc:resources mapping="/WebContent/images/**" location="images/"  />
<mvc:resources mapping="/WebContent/fonts/**" location="fonts/"  />

1 个答案:

答案 0 :(得分:1)

您的资源映射和链接标记的href属性存在问题。 由于您尚未发布目录结构 让我解释一下如何做样本图: 这是我的目录结构: enter image description here

如果我想将customestyle.min.css添加到我的html页面,我需要以下设置:

<mvc:resources mapping="/contents/css/**" location="/contents/css/" />

<link type="text/css" rel="stylesheet" href='<c:url value="/contents/css/customestyle.min.css"/> '/>