0

I have integrated spring security with thymeleaf and tiles but I got the following error when I run it:

WARN [btpool0-0] (DispatcherServlet.java:1114) - No mapping found for HTTP request with URI [/BMS/] in DispatcherServlet with name 'spring'

But when I write in the address bar localhost:8080/BMS/login.html, the page shows up
but when I try to call it by its view name like localhost:8080/BMS/loginView as I have configured it in the tiles-def.xml I got 404 not found

My web.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>BMS</display-name>
 <context-param>
<param-name>contextConfigLocation</param-name><param-value>
/WEB-INF/spring-security.xml
</param-value>
</context-param>
   <filter>
        <filter-name>encoding-filter</filter-name>
        <filter-class>
            org.springframework.web.filter.CharacterEncodingFilter
        </filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encoding-filter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
   </listener>
    <servlet>
    <servlet-name>default</servlet-name>
    <servlet-class>org.mortbay.jetty.servlet.DefaultServlet</servlet-class>
    <init-param>
      <param-name>useFileMappedBuffer</param-name>
      <param-value>false</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
  </servlet>
   <servlet>
   <servlet-name>spring</servlet-name>
   <servlet-class>
    org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>
     <servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/BMS/*</url-pattern>
    </servlet-mapping>
     <servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>BMS/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.gif</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.jpg</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.png</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/BMS/*</url-pattern>
</servlet-mapping>
 <filter>
      <filter-name>springSecurityFilterChain</filter-name>
      <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

  <welcome-file-list>
    <welcome-file>login.html</welcome-file>
       <welcome-file></welcome-file>
  </welcome-file-list>


</web-app>

tiles-def.xml

<tiles-definitions>
    <definition name="layout" template="templates/layout">
        <put-attribute name="header"   value="templates/header" />
        <put-attribute name="menu"   value="templates/menu" />
        <put-attribute name="footer" value="templates/footer" />
        <put-attribute name="body" />

    </definition>
    <definition name="loginView" extends="layout">
        <put-attribute name="body"   value="login.html" />
    </definition>
    <definition name="pages/usersView" extends="layout">
        <put-attribute name="body"   value="pages/users" />
    </definition>
     <definition name="pages/sendView" extends="layout">
        <put-attribute name="body"   value="pages/sendMessage" />
    </definition>
</tiles-definitions>

My security-servlet.xml is:

<?xml version="1.0" encoding="UTF-8"?>

<beans:beans xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
      <debug />
<global-method-security pre-post-annotations="enabled" />
<http pattern="/loginView" security="none"/>
    <http use-expressions="true">
        <intercept-url pattern="/resources/**" access="permitAll" />
        <intercept-url pattern="/templates/**" access="permitAll" />
        <intercept-url pattern="/pages/**" access="hasAuthority('User')" />
        <intercept-url pattern="/pages/admin/**" access="hasRole('Admin')"/>

          <form-login login-page="/loginView" authentication-failure-url="/loginView?error" default-target-url="/pages/usersView"/>

        <remember-me />

            <concurrency-control max-sessions="1" error-if-maximum-exceeded="true" />
        </session-management> -->

    </http>

    <authentication-manager>
        <authentication-provider>
             <user-service>
              <user name="admin" password="123" authorities="Admin,User" />
              <user name="user" password="111" authorities="User" />
             </user-service>
        </authentication-provider>
    </authentication-manager>

</beans:beans>

My LoginController is

 @RequestMapping("/loginView")
    public String login() {
        return "loginView";
    }

   // Login form with error
    @RequestMapping("/loginView")
    public String loginError(Model model) {
        model.addAttribute("loginError", true);
        return "loginView";
    }

Note: I have tried <url-pattern>/*</url-pattern> and <url-pattern>BMS/*</url-pattern> and <url-pattern>/</url-pattern> and <url-pattern>/BMS/*</url-pattern> in my springDispatcher in web xml but nothing worked

I also tried the solution in here. But it didn't help. What I am doing wrong?

Community
  • 1
  • 1
Dunken
  • 1,311
  • 7
  • 18
  • 30
  • Well, Spring MVC works with controllers (the C of MVC)... You have to define the Spring MVC servlet only once, and then do the mapping within controllers. Better read the [documentation](http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html) before using a framework ;) – sp00m Jun 24 '14 at 08:19
  • @sp00m thanks for the comment its working at the start now with no exception but when i call localhost:8080/BMS/pages/usersView it is try to redirect to loginView and give 404 not found – Dunken Jun 24 '14 at 08:39
  • Do you have any controller that handle the URL `/loginView`? – sp00m Jun 24 '14 at 08:42
  • @sp00m yes i do i have edited the question – Dunken Jun 24 '14 at 08:44

0 Answers0