当前位置: 首页 > 知识库问答 >
问题:

Spring 4 MVC,警告:在名为[…]的DispatcherServlet中找不到URI为HTTP请求的映射&HTTP 404错误

毕宇
2023-03-14

我的项目突然中断,调度器servlet无法转发到我的视图,我开始最初

警告:在名为'mvc_dispatcher'的Disp atcherServlet中找不到URI为[/theDallasapp_poc/]的HTTP请求的映射&浏览器中出现404错误。

在更改设置后,我在日志中没有错误。警告,但我只得到一个404错误。

以下是我的项目设置:

Java:1.6

Web框架:

下面是我的pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.hitachi</groupId>
    <artifactId>thedallasapp_poc_test</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>thedallasapp_poc_test</name>
    <url>http://maven.apache.org</url>


    <!-- properties -->
    <properties>
        <app.name>thedallassapp_poc</app.name>
        <tomcat.version>6.0.26</tomcat.version>
        <spring.version>4.0.0.RELEASE</spring.version>
        <hibernate.version>4.1.5.Final</hibernate.version>
        <spring.security.version>3.2.4.RELEASE</spring.security.version>
    </properties>

    <dependencies>

        <!-- jee -->
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
        </dependency>

        <!-- dependencies spring 4 -->

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>${spring.security.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>${spring.security.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-taglibs</artifactId>
            <version>${spring.security.version}</version>
        </dependency>


        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>


        <!-- Spring 4 dependencies END -->

        <!-- jdbc & database START -->
        <dependency>
            <groupId>postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.1-901-1.jdbc4</version>
        </dependency>
        <!-- connection pool -->
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-dbcp</artifactId>
            <version>7.0.52</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.1.Final</version>
        </dependency>


        <!-- jdbc & database END -->

        <!-- hibernate START -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <dependency>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.18.1-GA</version>
        </dependency>

        <!-- hibernate END -->

        <!-- junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <!-- jstl -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.1.1</version>

        </dependency>
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>

            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>c</artifactId>
            <version>1.1.1</version>

            <type>tld</type>
        </dependency>
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>fmt</artifactId>
            <version>1.1.1</version>

            <type>tld</type>
        </dependency>

        <!-- webapp-runner -->
        <dependency>
            <groupId>com.github.jsimone</groupId>
            <artifactId>webapp-runner</artifactId>
            <version>7.0.40.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <!-- build -->
    <build>
        <finalName>thedallasapp_poc</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <warFile>target/thedallasapp_poc.war</warFile>
                    <url>http://localhost:8080/manager/text</url>
                    <update>true</update>
                    <server>MyTomcat</server>
                    <path>/thedallasapp_poc</path>
                    <username>tomcat</username>
                    <password>password6678</password>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <!-- <packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes> -->
                    <packagingExcludes>WEB-INF/lib/tomcat*</packagingExcludes>
                    <source>1.6</source>
                    <target>1.6</target>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>copy</goal>
                            </goals>
                            <configuration>
                                <artifactItems>
                                    <artifactItem>
                                        <groupId>com.github.jsimone</groupId>
                                        <artifactId>webapp-runner</artifactId>
                                        <version>7.0.40.0</version>
                                        <destFileName>webapp-runner.jar</destFileName>
                                    </artifactItem>
                                </artifactItems>
                            </configuration>
                        </execution>
                    </executions>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

web.xml:

<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">

    <display-name>Toyota Relocation App</display-name>

    <servlet>
        <servlet-name>mvc_dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

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

    <!-- load spring security -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/mvc_dispatcher-servlet.xml,/WEB-INF/security.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- spring security -->
    <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>


</web-app>

Eclipse项目结构:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans     
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">


    <mvc:annotation-driven />
    <!-- scan at "com.hitachi.thedallasapp_poc" for spring annotated components 
        & register in spring container -->
    <context:annotation-config />

    <!-- <mvc:default-servlet-handler/>-->

    <context:component-scan base-package="com.hitachi.thedallasapp_poc.Category" />
    <context:component-scan base-package="com.hitachi.thedallasapp_poc.location" />
    <context:component-scan base-package="com.hitachi.thedallasapp_poc.messaging" />
    <context:component-scan base-package="com.hitachi.thedallasapp_poc.userprofile" />
    <context:component-scan base-package="com.hitachi.thedallasapp_poc.test" />

    <!-- the mvc resources tag that handles static content requests under resources 
        path -->
    <mvc:resources mapping="/resources/**" location="/resources/" />

    <!-- ViewResolver -->

    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/pages/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

    <!-- datasource & hibernate configs -->

    <bean id="myProperties"
        class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="locations">
            <list>
                <value>classpath*:db-dev.properties</value>
            </list>
        </property>
    </bean>

    <!-- local datasource -->

    <bean id="postgresqlDataSource" destroy-method="close"
        class="org.apache.tomcat.dbcp.dbcp.BasicDataSource">
        <property name="driverClassName" value="org.postgresql.Driver" />
        <property name="url"
            value="jdbc:postgresql://localhost:5432/postgres?createDatabaseIfNotExist=true" />
        <property name="username" value="postgres" />
        <property name="password" value="heroku6678" />
    </bean>

    <!-- hibernate sessionFactoty via properties -->
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

        <property name="dataSource" ref="postgresqlDataSource" />

            <!-- annotated classes -->
        <property name="annotatedClasses">
            <list>
                <value>com.hitachi.thedallasapp_poc.userprofile.UserProfile</value>
                <value>com.hitachi.thedallasapp_poc.userprofile.UserConnection</value>
                <value>com.hitachi.thedallasapp_poc.Category.Categories</value>
                <value>com.hitachi.thedallasapp_poc.location.Location</value>
                <value>com.hitachi.thedallasapp_poc.location.FavoriteLocation</value>
                <value>com.hitachi.thedallasapp_poc.messaging.Messages</value>
            </list>
        </property>
         <property name="hibernateProperties">
            <props>
                <prop key="hibernate.hbm2ddl.auto">create</prop>
                <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.temp.use_jdbc_metadata_defaults">false</prop> 
            </props>
        </property>

    </bean>

    <!-- transaction management -->
    <bean id="txManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
        <property name="dataSource" ref="postgresqlDataSource" />
    </bean>


    <bean id="persistenceExceptionTranslationPostProcessor"
        class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

</beans>
<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-3.0.xsd
           http://www.springframework.org/schema/security
           http://www.springframework.org/schema/security/spring-security-3.2.xsd">

    <!-- spring security should ignore "/" & "/resources/**" paths -->
    <http pattern="/" security="none" auto-config="true"
        use-expressions="true" />
    <http pattern="/login" security="none" auto-config="true"
        use-expressions="true" />
    <http pattern="/resources/**" security="none" auto-config="true"
        use-expressions="true" />

    <!-- custom bean used to override spring security page redirection after 
        successful authentication -->
    <beans:bean id="myAuthSuccessHandler"
        class="com.hitachi.thedallasapp_poc.security.MyAuthSuccessHandler" />


    <!-- spring security configuration intercept-url & login form -->
    <http auto-config="true" use-expressions="true">
        <intercept-url pattern="/auth/**" access="hasRole('ROLE_USER')" />

        <form-login login-page="/login" authentication-failure-url="/login?error"
            username-parameter="emailInputField" password-parameter="pinInputField"
            default-target-url="/auth/welcome" always-use-default-target="true"
            authentication-success-handler-ref="myAuthSuccessHandler" />
        <!-- keep logged in session for 3 days or 259200 secs -->
        <remember-me key="uniqueAndSecret1984"
            token-validity-seconds="60" />

        <logout logout-url="/logout" logout-success-url="/login?logout=1"
            delete-cookies="JSESSIONID" invalidate-session="true" />

    </http>

    <!-- user accounts -->
    <authentication-manager>
        <authentication-provider>
            <user-service>
                <user name="naim@test.com" password="12345" authorities="ROLE_USER" />
            </user-service>
        </authentication-provider>
    </authentication-manager>

</beans:beans>
package com.hitachi.thedallasapp_poc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.security.authentication.RememberMeAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class HomeControler {

    public HomeControler() {
        super();
        // TODO Auto-generated constructor stub
    }

    /* serves the login landing/home page view */
    @RequestMapping(value="/")
    public ModelAndView serveLanding(HttpSession session) {



        ModelAndView model = new ModelAndView();
        model.setViewName("login");
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        //check if isRememberMeAuthenticated cookie is true from previous login 
        System.out.println("Class HomeControler, String serveLanding(), isRememberMeAuthenticated():"+isRememberMeAuthenticated());
        if (isRememberMeAuthenticated()!=false && auth.isAuthenticated()!=false)    
        {
            session.setAttribute("isRememberMeAuthenticated", true);

        }

        return model;
    }

    /* process login request from login view */
    @RequestMapping(value = "/login**")
    public ModelAndView processLogin(String error,@RequestParam(value = "logout", required = false) String logout)
    {
        System.out.println("Class HomeControler,  processLogin()");
        ModelAndView model = new ModelAndView();

         //non test code

        if (error != null) {
            System.out.println("Class HomeControler,  processLogin(), error ");
            model.addObject("error", "Invalid username and password!");

        }
            if (logout != null) {
                System.out.println("Class HomeControler,  processLogin(), logout ");
                model.addObject("msg", "You've been logged out successfully.");

            }

            model.setViewName("login");


            return model;

    }


    /* serves the login landing/home page view */
    @RequestMapping(value="/auth/welcome**")
    public ModelAndView welcome(HttpSession session) {

        System.out.println("Class HomeControler, String welcome()");

        ModelAndView model = new ModelAndView();

        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        //after authentication check isRememberMeAuthenticated cookie is true
        System.out.println("Class HomeControler, String welcome(), isRememberMeAuthenticated():"+isRememberMeAuthenticated());

               if (isRememberMeAuthenticated()!=false && auth.isAuthenticated()!=false) 
                {

                    session.setAttribute("isRememberMeAuthenticated", true);

                }
        //get logged in username

        String name = auth.getName();
        model.addObject("loggedInUserName", name);
        model.setViewName("/auth/appView");

        return model;
    }


    /* serves the login landing/home page view */
    @RequestMapping(value="/logout")
    public  ModelAndView logoutTheUserAndInvalidateSession(HttpSession session, HttpServletRequest request, HttpServletResponse response) {

        ModelAndView model = new ModelAndView();
        //logout via spring security 
         Authentication auth = SecurityContextHolder.getContext().getAuthentication(); 
            SecurityContextLogoutHandler ctxLogOut = new SecurityContextLogoutHandler();
                ctxLogOut.logout(request, response, auth); 
            //invalidate session just to make sure 
                session = request.getSession(false);
                if (session != null) {
                    session.invalidate();
                }

                model.addObject("logout","1");
                model.setViewName("login");

    return model;
    }


    /**
     * Check if user is login by remember me cookie, refer
     * org.springframework.security.authentication.AuthenticationTrustResolverImpl
     */
    private boolean isRememberMeAuthenticated() {

        Authentication authentication = 
                    SecurityContextHolder.getContext().getAuthentication();
        if (authentication == null) {
            return false;
        }

        return RememberMeAuthenticationToken.class.isAssignableFrom(authentication.getClass());
    }

    }//end class HomeControler

登录视图:

<!DOCTYPE html>
<html>
<head>
<title>Toyota Relocation App</title>
<meta name="viewport"
    content="width=device-width, initial-scale=1, user-scalable=no">
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec"
    uri="http://www.springframework.org/security/tags"%>
<!-- jquery styles & scripts -->
<script
    src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
    $(document).bind("mobileinit", function() {
        $.mobile.ajaxEnabled = false;
    });
</script>
<script>
    $(document).ready(function() {

        // if error has data then make div visible
        <c:if test="${not empty error}">
        if ($('.error_div').length > 0) {
            console.log("found .error_div");
            $('.error_div').show();
        }
        </c:if>
        // if msg has data then make div visible
        <c:if test="${not empty msg}">
        if ($('.msg_div').length > 0) {
            console.log("found .msg_div");
            $('.msg_div').show();
        }
        </c:if>
    });
</script>
<link rel="stylesheet"
    href="//ajax.googleapis.com/ajax/libs/jquerymobile/1.4.2/jquery.mobile.min.css" />
<script
    src="//ajax.googleapis.com/ajax/libs/jquerymobile/1.4.2/jquery.mobile.min.js"></script>
<!--  http://fortawesome.com -->
<link
    href="http://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css"
    rel="stylesheet">
<!-- custom stylesd & scripts -->
<link rel="stylesheet" href="resources/css/home.css" />
<script type="text/javascript" src="resources/js/home.js"></script>
</head>
<body>
    <!--  
<sec:authorize access="hasRole('ROLE_USER')">
<script>
console.log("hasRole('ROLE_USER')");
$.post( "./auth/app" );
</script>
</sec:authorize>
-->
    <div class="wrapper">

        <!-- 
        <div data-role="header" data-position="fixed">
            <div class="myheader">HEADER</div>
        </div>
        -->

        <div data-role="content">

            <div class="mycontent">
                <div id="logo_div">
                    <img src="resources/images/01_toyota_logo_small.png">
                </div>
                <div class="login_form_wrapper">
                    <!--  login error & msg jstl -->
                    <div class="error_div" style="display: none;">
                        <p class="error_text">${error}</p>
                    </div>
                    <div class="msg_div" style="display: none;">
                        <p class="msg_text">${msg}</p>
                    </div>
                    <!-- spring security form -->
                    <form name='loginForm'
                        action="<c:url value='/j_spring_security_check' />" method='POST'>

                        <ul class="mylistview" data-role="listview">
                            <li>
                                <div>
                                    <img id="email_input_icon"
                                        src="resources/images/01_login_email_icon_small.png">
                                </div>
                                <div id="email_input">
                                    <input name="emailInputField" " id="email_input_field"
                                        type="email" data-role="none" />
                                </div>
                            </li>
                            <li>
                                <div>
                                    <img id="pin_input_icon"
                                        src="resources/images/01_login_password_icon_small.png">
                                </div>
                                <div id="pin_input">
                                    <input name="pinInputField" id="pin_input_field"
                                        type="password" data-role="none" />
                                </div>
                            </li>
                            <li>

                                <div id="login_button">
                                    <button id="login" class="button" type="submit">LOGIN</button>
                                </div>
                                <div id="remember">
                                    <label class="checkboxLabel" data-role="none"
                                        style="float: left">
                                        <p>Remember Me</p>
                                    </label> <input data-role="none" type='checkbox'
                                        name='_spring_security_remember_me'
                                        id="_spring_security_remember_me" value="true" />
                                </div>
                            </li>
                        </ul>

                    </form>
                </div>

                <div class="or_divider">
                    <img src="resources/images/01_login_or_option_small.png">
                </div>

                <div class="options_menu">

                    <ul class="mylistview2" data-role="listview">
                        <li>
                            <div id="login_account_no_words_icon">
                                <img src="resources/images/01_login_account_no_words_small.png">
                            </div>
                            <div id="login_guest_no_words_icon">
                                <img src="resources/images/01_login_guest_no_words_small.png">
                            </div>
                        </li>
                        <li>
                            <div id="create_an_account">
                                <P>Create An Account</P>
                            </div>
                            <div id="continue_as_guest">
                                <P>Continue As Guest</P>
                            </div>
                        </li>

                    </ul>
                </div>
            </div>

        </div>
        <!-- 
        <div data-role="footer">
            <div class="myfooter">FOOTER</div>
        </div>
        -->
    </div>
</body>

</html>

通过Eclipse进行部署:

我通过Eclipse部署到Tomcat的方法是:右键单击我的项目,选择Run As,选择Tomcatv7.0,选择Finish...

结果:

最后,我将web.xml Dispatcher servlet-name映射更改为“/thedallasapp_poc*”,而不是“/”:

web.xml片段:

<servlet>
        <servlet-name>mvc_dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>mvc_dispatcher</servlet-name>
        <url-pattern>/thedallasapp_poc*</url-pattern>
    </servlet-mapping>

因此,我还将HomeController从@RequestMapping(value=“/”)更改为@RequestMapping(value=“/TheDallasApp_Poc”)

public HomeControler() {
    super();
    // TODO Auto-generated constructor stub
}

/* serves the login landing/home page view */
@RequestMapping(value="/thedallasapp_poc")
public ModelAndView serveLanding(HttpSession session) {



    ModelAndView model = new ModelAndView();
    model.setViewName("login");
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    //check if isRememberMeAuthenticated cookie is true from previous login 
    System.out.println("Class HomeControler, String serveLanding(), isRememberMeAuthenticated():"+isRememberMeAuthenticated());
    if (isRememberMeAuthenticated()!=false && auth.isAuthenticated()!=false)    
    {
        session.setAttribute("isRememberMeAuthenticated", true);

    }

    return model;
}

共有1个答案

谷出野
2023-03-14
<context:component-scan base-package="com.hitachi.thedallasapp_poc.Category"/>

上面一行将扫描com.hitachi.theDallasapp_poc.category包中可用的所有组件

并且它不会扫描com.hitachi.theDallasapp_poc包中的组件。

类似地,我可以在com.hitachi.thedallasapp_poc主包中看到所有组件扫描引用子包

<context:component-scan base-package="com.hitachi.thedallasapp_poc"/>
 类似资料: