SpringMVC的问题No mapping found for HTTP request with URI

做了一个屏蔽进数据库的操作:

Applicaition.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:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.2.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd">

    <!-- 配置数据源,记得去掉myBatis-config.xml的数据源相关配置 -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="com.mysql.jdbc.Driver" />
        <property name="jdbcUrl"
            value="jdbc:mysql://localhost:3306/mybatis2?useUnicode=true&amp;characterEncoding=UTF-8" />
        <property name="user" value="root" />
        <property name="password" value="123456" />
    </bean>
    <!-- 配置session工厂 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation" value="classpath:mybatis-config.xml" />
    </bean>

    <!-- 配置事务管理器,管理数据源事务处理 -->
    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>
    <!-- 配置事务通知 -->
    <tx:advice id="advice" transaction-manager="transactionManager">
        <tx:attributes>
            <!-- 默认只处理运行时异常,可加rollback-for="Exception/Throwable"等处理所有异常或包括错误 -->
            <tx:method name="insert*" propagation="REQUIRED"
                rollback-for="Exception" />
            <tx:method name="update*" propagation="REQUIRED"
                rollback-for="Exception" />
            <tx:method name="delete*" propagation="REQUIRED"
                rollback-for="Exception" />
            <tx:method name="*" propagation="SUPPORTS" />
        </tx:attributes>
    </tx:advice>

    <!-- 配置SessionTemplate,已封装了繁琐的数据操作 -->
    <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate"
        scope="prototype">
        <constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory" />
    </bean>

    <!-- 配置切面织入的范围,后边要把事务边界定在service层 -->
    <aop:config>
        <aop:advisor advice-ref="advice"
            pointcut="execution(* com.liuyang.crm.service.Imp.*.*(..))" />
    </aop:config>

    <context:component-scan base-package="com.liuyang" />
    <!--context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"
        /> </context:component-scan -->

</beans>

防止错误数据进入的屏蔽

 <context:component-scan base-package="com.liuyang" />
    <!--context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"
        /> </context:component-scan -->

这里其实注销掉,也是好使的.加上了就出现文章上边的找不到url地址注入的错误.

spring-mvc.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:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
    ">

    <!-- 同时开启json格式的支持 -->
    <mvc:annotation-driven></mvc:annotation-driven>

    <context:component-scan base-package="com.liuyang">
        <context:include-filter type="annotation"
            expression="org.springframework.stereotype.Controller" />
        <context:exclude-filter type="annotation"
            expression="org.springframework.stereotype.Service" />
    </context:component-scan>

</beans>

这里配置屏蔽就可以,这样数据库同样不进错误数据.

<context:component-scan base-package="com.liuyang">
        <context:include-filter type="annotation"
            expression="org.springframework.stereotype.Controller" />
        <context:exclude-filter type="annotation"
            expression="org.springframework.stereotype.Service" />
    </context:component-scan>
@Override
	public int insertDept(Dept dept) throws Exception {
		int i = 0;
		i = deptDao.insertDept(dept);
		Integer.parseInt("aa");
		return i;
	}

希望对您有帮助,感谢您的观看.

时间: 2024-10-30 09:03:51

SpringMVC的问题No mapping found for HTTP request with URI的相关文章

[org.springframework.web.servlet.PageNotFound] -No mapping found for HTTP request with URI [/homework/js/jquery-1.7.2.min.js] in DispatcherServlet with name &#39;SpringMVC&#39;

先上解决方案:对于上面出现的问题,查看了很多相关的博客,论坛.最后实在Spring-mvc.xml这个配置文件里加入了如下两行: 1 <mvc:annotation-driven /> 2 <mvc:default-servlet-handler /> 问题描述: 由于项目需要Ajax,于是在jsp的head里加入了如下代码: 1 <script type="text/javascript" src="/homework/js/jquery-1.

java springmvc No mapping found for HTTP request with URI

最近,想写一个全文搜索的工具,想着就是用springMVC+lucene+tika来完成,当把整个架构都搭建好了以后,发现springmvc配置的control总是映射不到,总是报No mapping found for HTTP request with URI,导致无法执行逻辑层: 经过两天的不断尝试(期间spring源码都翻看了一些,而且通过调试spring代码找原因,最终也没找到),偶然之间觉得使用maven的clean和install的方式打成war试了一下,居然问题不存在了.考虑了一

相对路径获取项目文件 及报错 No mapping found for HTTP request with URI XXX in DispatcherServlet with name ‘springmvc’解决方法

首先一点,WebRoot目录下的文件是都可以通过浏览器输入路径,直接读取到的 例如这样: 而WebRoot下面WEB-INF是无法浏览器输入路径直接读取的. 因为是受保护的. 如果jsp读取一个图片的话. jsp在WebRoot/jsp下 图片在WebRoot/imag下 那么就要../imag/xx.jpg获取相对路径. 因为servlet程序是无法读取C:\xx\xx\xx这样的绝对路径的. 除非更改tomcat配置文件,但我觉得那样完全没有意义. 另外,要注意你请求的路径是否被拦截. 例如

org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [XXX] in DispatcherServlet with name &#39;springMVC&#39;

在web.xml中添加 <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.ico</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.png<

springmvc No mapping found for HTTP request with URI in Dispatc

项目是使用spring MVC (1)在浏览器中访问,后台总报错: Java代码   No mapping found for HTTP request with URI [/exam3/welcome] in DispatcherServlet with name 'spring2' 查了好半天,才发现是controller 没有扫描到. 我是使用的注解. spring mvc配置文件如下: Xml代码   <?xml version="1.0" encoding="

SpringMVC - 问题. No mapping found for HTTP request with URI

<bean id="viewResolver"        class="org.springframework.web.servlet.view.InternalResourceViewResolver">        <property name="prefix" value="/WEB-INF/html/" />        <property name="suffix&qu

No mapping found for HTTP request with URI [/Portal/download] in DispatcherServlet with name &#39;springmvc&#39;

本文为博主原创,未经允许不得转载: 遇到这个异常,总结一下这个问题发生的原因: 这个原因是在springmvc中在DispatcherServlet分发请求时,解析不到相应的请求路径.后台要请求的路径应该是"/portal/download", 由于portal中的第一个单词大写了,在请求的时候就没解析到路径,所以报此错. 修改过之后就可以正常请求了. 还有报此异常的可能是由于在springmvc扫描注解时,没有扫描到也会报此错误. No mapping found for HTTP

springmvc搭建环境时报No mapping found for HTTP request with URI [/exam3/welcome] in DispatcherServlet with name &#39;spring2&#39;

项目是使用spring MVC (1)在浏览器中访问,后台总报错: Java代码   No mapping found for HTTP request with URI [/exam3/welcome] in DispatcherServlet with name 'spring2' 查了好半天,才发现是controller 没有扫描到. 我是使用的注解. spring mvc配置文件如下: Xml代码   <?xml version="1.0" encoding="

No mapping found for HTTP request with URI [/crmcrmcrm/css/bootstrap.min.css] in DispatcherServlet with name &#39;springMvc&#39;

先把错误贴上来 No mapping found for HTTP request with URI [/crmcrmcrm/css/sb-admin-2.css] in DispatcherServlet with name 'springMvc'DEBUG [http-bio-8080-exec-6] - Successfully completed requestDEBUG [http-bio-8080-exec-7] - Did not find handler method for [