欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

待解决 No mapping found for HTTP request with URI [/cloudPlatformSystem/login.action] in DispatcherS

程序员文章站 2022-07-15 13:11:40
...

web,xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                      http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
	version="3.1" metadata-complete="true">
	<!-- 修改servlet版本为3.1 -->

	  <display-name>HuaWei</display-name>
		  <welcome-file-list>
		    <welcome-file>/webapp/index.html</welcome-file>
		    <welcome-file>/webapp/index.htm</welcome-file>
		    <welcome-file>/webapp/index.jsp</welcome-file>
		    <welcome-file>default.html</welcome-file>
		    <welcome-file>default.htm</welcome-file>
		    <welcome-file>default.jsp</welcome-file>
		  </welcome-file-list>
	
	
	  <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:applicationContext.xml</param-value>
   	 </context-param>
	
		  
	<filter>
		<filter-name>encodingFilter</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>encodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<!-- 启用Restful风格的URI 将页面普通的post转为制定的delete或者put -->
	 <filter>
		<filter-name>HiddenHttpMethodFilter</filter-name>
		<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
	</filter> 



	<!-- spring环境加载监听器,用于加载spring配置文件及初始化spring运行环境 -->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<!-- 自省清理监听器,用于清理spring运行时可能产生的内存泄漏 -->
	<listener>
		<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
	</listener>

	<!-- 配置DispatcherServlet -->
	<servlet>
		<servlet-name>dispatcherServlet</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
	<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath*:/WEB-INF/dispatcherServlet-servlet.xml</param-value>
		</init-param>	
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>dispatcherServlet</servlet-name>
		<!-- 默认匹配所有的请求 -->
        <url-pattern>*.action</url-pattern>
	
	</servlet-mapping>


</web-app>

dispatcherServlet-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans.xsd
	http://www.springframework.org/schema/context
	http://www.springframework.org/schema/context/spring-context-4.0.xsd
	http://www.springframework.org/schema/mvc
	http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">

	<!-- 注解扫描包 -->
	<context:component-scan base-package="com.huawei.cloud.controller"></context:component-scan>

	<mvc:default-servlet-handler />
	
	<mvc:annotation-driven /> 
		
		<!-- 开启注解 -->
	<mvc:annotation-driven conversion-service="conversionService" />

	<!--配置视图解释器,方面页面放回 -->
	<bean id="viewResolver"
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		
		<property name="prefix" value="/WEB-INF/"></property>
		<property name="suffix" value=".jsp" /> 
	</bean>


<!--
		配置静态资源,直接映射到对应的文件夹,不被DispatcherServlet处理,3.04新增功能,需要重新设置spring-mvc-3.0.xsd
	-->
	<mvc:resources mapping="/img/**" location="/img/" />
	<mvc:resources mapping="/js/**" location="/js/" />
	<mvc:resources mapping="/css/**" location="/css/" />
	<mvc:resources mapping="/static/**" location="/static/" />


</beans>

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">

	<context:component-scan base-package="com.huawei.cloud.service"/>
	
	<context:property-placeholder location="classpath:dbconfig.properties"/>	
	<bean id="pooledDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
		<property name="driverClass" value="${jdbc.driverClass}"></property>
		<property name="user" value="${jdbc.user}"></property>
		<property name="password" value="${jdbc.password}"></property>
	</bean>				
	
		<!-- 2. mybatis的SqlSession的工厂: SqlSessionFactoryBean dataSource:引用数据源 MyBatis定义数据源,同意加载配置 -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="configLocation" value="classpath:mybatis-config.xml"></property>
		<property name="dataSource" ref="pooledDataSource"></property>	
		<property name="mapperLocations" value="classpath:mapper/*.xml"></property>
	</bean>	
	
	<!--配置扫描器,将mybatis接口的实现加入到ioc容器中  -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<!--扫描所有的接口,加入到ioc容器中  -->
		<property name="basePackage" value="com.huawei.cloud.dao"></property>
<!-- 		<property name="sqlSessionFactory" ref="sqlSessionFactory"></property>	 -->
	</bean>	
		<!-- 事务控制 -->
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
	<!--	控制数据源你-->
		<property name="dataSource" ref="pooledDataSource"></property>
	</bean>	
		
	<aop:config>
		<aop:pointcut expression="execution(* com.huawei.cloud.service..*(..))" id="txPoint"/>
		<aop:advisor advice-ref="txAdvice"  pointcut-ref="txPoint"/>
	</aop:config>

	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes >
			<tx:method name="*"/>
			<tx:method name="get*" read-only="true"/>			
		</tx:attributes>
	</tx:advice>

</beans>

mybatis-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
  PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>
	<settings>
		<setting name="mapUnderscoreToCamelCase" value="true"></setting>
	</settings>
	<typeAliases>
		<package name="com.huawei.cloud.bean"/>
	</typeAliases>

</configuration>


index.jsp`

<form class="login-form" action="${pageContext.request.getContextPath()}/login.action" method="post">
				<h1>Welcome</h1>
				<input class="txtb" type="text" name="username" placeholder="Username" >
				<input class="txtb"	type="text" name="password" placeholder="Password" >			
				<input class="login-btn" type="submit" value="Login" >
			</form>				

controller层

package com.huawei.cloud.controller;

import javax.servlet.http.HttpSession;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.huawei.cloud.bean.User;
import com.huawei.cloud.service.UserService;

@Controller
@RequestMapping
public class UserController {
	
	@Autowired
	private UserService userService;
	
	@RequestMapping(value="/login",method=RequestMethod.POST)	
	public String  checkedLogin(@Param("username") String username,@Param("password")String password,HttpSession session) {
		System.out.println(username +"--"+password);//没有输出
		User user =userService.checkedLogin(username, password);
		
		if (user!=null && user.getRole()!=0) {
			session.setAttribute("user", user);
		
				return "admin-main";				
			
		}else if (user!=null && user.getRole()==1) {
			session.setAttribute("user", user);
				return "user-main";		
		}
		
		return "index";
	}
	
}

出现的bug

  1. Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping’: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.web.servlet.handler.MappedInterceptor#0’: Cannot create inner bean ‘(inner bean)#893081e’ of type [org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘(inner bean)#893081e’: Cannot resolve reference to bean ‘conversionService’ while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ‘conversionService’ available

初始化错误
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘loginController’: Unsatisfied dependency expressed through field ‘userService’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘userServiceImpl’: Unsatisfied dependency expressed through field ‘userMapper’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘com.huawei.cloud.dao.UserMapper’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
四月 26, 2019 5:43:20 下午 org.springframework.web.context.ContextLoader initWebApplicationContext
严重: Context initialization failed
3. List item
严重: Servlet.init() for servlet [dispatcherServlet] threw exception
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping’: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.web.servlet.handler.MappedInterceptor#0’: Cannot create inner bean ‘(inner bean)#275b98d5’ of type [org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘(inner bean)#275b98d5’: Cannot resolve reference to bean ‘conversionService’ while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ‘conversionService’ available
4. List item
警告: No mapping found for HTTP request with URI [/cloudPlatformSystem/login.action] in DispatcherServlet with name ‘dispatcherServlet’

相关标签: ssm