最近搭建一个web项目后端SSM框架练手,使用Maven管理,遇到一个深坑invalid bound statement (not found),就是mapper文件扫描不到!!!

先上整合过程,解决办法最后上。

1、项目结构:

2、pom文件:

<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.bolue</groupId>
<artifactId>oa</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>oa Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<junit.version>4.12</junit.version>
<spring.version>4.1.3.RELEASE</spring.version>
<mybatis.version>3.2.8</mybatis.version>
<mybatis.spring.version>1.2.2</mybatis.spring.version>
<mybatis.paginator.version>1.2.15</mybatis.paginator.version>
<mysql.version>5.1.32</mysql.version>
<slf4j.version>1.6.4</slf4j.version>
<jackson.version>2.4.2</jackson.version>
<druid.version>1.0.9</druid.version>
<httpclient.version>4.3.5</httpclient.version>
<jstl.version>1.2</jstl.version>
<servlet-api.version>2.5</servlet-api.version>
<jsp-api.version>2.0</jsp-api.version>
<joda-time.version>2.5</joda-time.version>
<commons-lang3.version>3.3.2</commons-lang3.version>
<commons-io.version>1.3.2</commons-io.version>
<commons-net.version>3.3</commons-net.version>
<pagehelper.version>3.4.2-fix</pagehelper.version>
<jsqlparser.version>0.9.1</jsqlparser.version>
<commons-fileupload.version>1.3.1</commons-fileupload.version>
<jedis.version>2.7.2</jedis.version>
<solrj.version>4.10.3</solrj.version>
</properties>
<dependencies>
<!-- 时间操作组件 -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda-time.version}</version>
</dependency>
<!-- Apache工具组件 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>${commons-net.version}</version>
</dependency>
<!-- Jackson Json处理工具包 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<!-- httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<!-- 单元测试 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- 日志处理 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!-- Mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${mybatis.spring.version}</version>
</dependency>
<dependency>
<groupId>com.github.miemiedev</groupId>
<artifactId>mybatis-paginator</artifactId>
<version>${mybatis.paginator.version}</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>${pagehelper.version}</version>
</dependency>
<!-- MySql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<!-- 连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- JSP相关 -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>${jsp-api.version}</version>
<scope>provided</scope>
</dependency>
<!-- 文件上传组件 -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>${commons-fileupload.version}</version>
</dependency>
<!-- Redis客户端 -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${jedis.version}</version>
</dependency>
<!-- solr客户端 -->
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>${solrj.version}</version>
</dependency>
</dependencies>
<build>
<finalName>oa</finalName>
<!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<!-- 资源文件拷贝插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- java编译插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- Tomcat插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>8080</port>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
</project>

导入的包有点多,可以根据自己需要选择导入。

3、:db.properties文件:

driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/test?characterEncoding=utf-8&allowMultiQueries=true
username=root
password=root

#\u5b9a\u4e49\u521d\u59cb\u8fde\u63a5\u6570
initialSize=0
#\u5b9a\u4e49\u6700\u5927\u8fde\u63a5\u6570
maxActive=20
#\u5b9a\u4e49\u6700\u5927\u7a7a\u95f2
maxIdle=20
#\u5b9a\u4e49\u6700\u5c0f\u7a7a\u95f2
minIdle=1
#\u5b9a\u4e49\u6700\u957f\u7b49\u5f85\u65f6\u95f4
maxWait=60000

4、log4j文件:
log4j.rootLogger=info,fileAppender,consoleAppender

#\u6253\u5370\u65e5\u5fd7\u5230\u63a7\u5236\u53f0\uff0c\u5982\u9700\u8981\u6b64\u529f\u80fd,\u5728\u7b2c\u4e00\u884c\u672b\u5c3e\u52a0\u4e0a\u5185\u5bb9\uff1a,consoleAppender
log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender
log4j.appender.consoleAppender.Target = System.out
log4j.appender.consoleAppender.layout = org.apache.log4j.PatternLayout
log4j.appender.consoleAppender.layout.ConversionPattern = %d %p %c %L %M - %m%x%n

#\u6253\u5370\u7cfb\u7edf\u65e5\u5fd7\u5230\u6587\u4ef6
log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.fileAppender.File=../logs/pats-client/pats-client.log
log4j.appender.fileAppender.DatePattern = '_'yyyyMMdd
log4j.appender.fileAppender.layout = org.apache.log4j.PatternLayout
log4j.appender.fileAppender.layout.ConversionPattern = %d %p %c %L %M - %m%x%n

#source\u65e5\u5fd7
log4j.logger.com.pats.client.log.datalog.SourceDataLog=INFO,sourceDataLog
log4j.appender.sourceDataLog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.sourceDataLog.File=../logs/pats-client/source_data.log
log4j.appender.sourceDataLog.DatePattern = '_'yyyyMMdd
log4j.appender.sourceDataLog.layout = org.apache.log4j.PatternLayout
log4j.appender.sourceDataLog.layout.ConversionPattern = [%d]%m%x%n
log4j.additivity.com.pats.client.log.datalog.SourceDataLog = false

#websocket\u6570\u636e\u65e5\u5fd7
log4j.logger.com.pats.client.log.AskPriceModelDataLog = DEBUG,AskPriceDataLog
log4j.appender.AskPriceDataLog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.AskPriceDataLog.File=../logs/pats-client/askPrice_data.log
log4j.appender.AskPriceDataLog.DatePattern = '_'yyyyMMdd
log4j.appender.AskPriceDataLog.layout=org.apache.log4j.PatternLayout
log4j.appender.AskPriceDataLog.layout.ConversionPattern=%d %p %c %L %M - %m%x%n
log4j.additivity.com.pats.client.log.AskPriceModelDataLog = false

#websocket\u6570\u636e\u65e5\u5fd7
log4j.logger.com.pats.client.log.BidPriceModelDataLog = DEBUG,BidPriceDataLog
log4j.appender.BidPriceDataLog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.BidPriceDataLog.File=../logs/pats-client/bidPrice_data.log
log4j.appender.BidPriceDataLog.DatePattern = '_'yyyyMMdd
log4j.appender.BidPriceDataLog.layout=org.apache.log4j.PatternLayout
log4j.appender.BidPriceDataLog.layout.ConversionPattern=%d %p %c %L %M - %m%x%n
log4j.additivity.com.pats.client.log.BidPriceModelDataLog = false

#websocket\u6570\u636e\u65e5\u5fd7
log4j.logger.com.pats.client.log.DealLogModelDataLog = DEBUG,DealLogDataLog
log4j.appender.DealLogDataLog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.DealLogDataLog.File=../logs/pats-client/dealLog_data.log
log4j.appender.DealLogDataLog.DatePattern = '_'yyyyMMdd
log4j.appender.DealLogDataLog.layout=org.apache.log4j.PatternLayout
log4j.appender.DealLogDataLog.layout.ConversionPattern=%d %p %c %L %M - %m%x%n
log4j.additivity.com.pats.client.log.DealLogModelDataLog = false

#websocket\u6570\u636e\u65e5\u5fd7
log4j.logger.com.pats.client.log.FullModelDataLog = DEBUG,FullDataLog
log4j.appender.FullDataLog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.FullDataLog.File=../logs/pats-client/full_data.log
log4j.appender.FullDataLog.DatePattern = '_'yyyyMMdd
log4j.appender.FullDataLog.layout=org.apache.log4j.PatternLayout
log4j.appender.FullDataLog.layout.ConversionPattern=%d %p %c %L %M - %m%x%n
log4j.additivity.com.pats.client.log.FullModelDataLog = false

#websocket\u6570\u636e\u65e5\u5fd7
log4j.logger.com.pats.client.log.PositionModelDataLog = DEBUG,PositionDataLog
log4j.appender.PositionDataLog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.PositionDataLog.File=../logs/pats-client/position_data.log
log4j.appender.PositionDataLog.DatePattern = '_'yyyyMMdd
log4j.appender.PositionDataLog.layout=org.apache.log4j.PatternLayout
log4j.appender.PositionDataLog.layout.ConversionPattern=%d %p %c %L %M - %m%x%n
log4j.additivity.com.pats.client.log.PositionModelDataLog = false

#websocket\u6570\u636e\u65e5\u5fd7
log4j.logger.com.pats.client.log.VwapModelDataLog = DEBUG,VwapDataLog
log4j.appender.VwapDataLog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.VwapDataLog.File=../logs/pats-client/vwap_data.log
log4j.appender.VwapDataLog.DatePattern = '_'yyyyMMdd
log4j.appender.VwapDataLog.layout=org.apache.log4j.PatternLayout
log4j.appender.VwapDataLog.layout.ConversionPattern=%d %p %c %L %M - %m%x%n
log4j.additivity.com.pats.client.log.VwapModelDataLog = false

#websocket\u6570\u636e\u65e5\u5fd7
log4j.logger.com.pats.client.log.ProductDataLog = DEBUG,ProductDataLog
log4j.appender.ProductDataLog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.ProductDataLog.File=../logs/pats-client/product_data.log
log4j.appender.ProductDataLog.DatePattern = '_'yyyyMMdd
log4j.appender.ProductDataLog.layout=org.apache.log4j.PatternLayout
log4j.appender.ProductDataLog.layout.ConversionPattern=%d %p %c %L %M - %m%x%n
log4j.additivity.com.pats.client.log.ProductDataLog = false

#websocket\u6570\u636e\u65e5\u5fd7
log4j.logger.com.pats.client.log.ProductErrorDataLog = DEBUG,ProductErrorDataLog
log4j.appender.ProductErrorDataLog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.ProductErrorDataLog.File=../logs/pats-client/productError_data.log
log4j.appender.ProductErrorDataLog.DatePattern = '_'yyyyMMdd
log4j.appender.ProductErrorDataLog.layout=org.apache.log4j.PatternLayout
log4j.appender.ProductErrorDataLog.layout.ConversionPattern=%d %p %c %L %M - %m%x%n
log4j.additivity.com.pats.client.log.ProductErrorDataLog = false

#jdbc\u65e5\u5fd7
#log4j.logger.org.springframework.jdbc=debug
#log4j.logger.org.mybatis.spring=debug
#log4j.logger.com.pats.client.dao=debug

5、spring-mybatis.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"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="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.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.1.xsd">
<!-- 自动扫描 -->
<context:component-scan base-package="com.bolue.oa"/>
<!-- 引入配置文件 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:db.properties"/>
</bean>
<!-- 数据源 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
<!-- 初始化连接大小 -->
<property name="initialSize" value="${initialSize}" />
<!-- 连接池最大使用连接数量 -->
<property name="maxActive" value="${maxActive}" />
<!-- 连接池最大空闲 -->
<!-- <property name="maxIdle" value="${maxIdle}" /> -->
<!-- 连接池最小空闲 -->
<property name="minIdle" value="${minIdle}" />
<!-- 获取连接最大等待时间 -->
<property name="maxWait" value="${maxWait}" />
<property name="validationQuery" value="SELECT 1" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="25200000" />
<property name="filters" value="mergeStat" />
</bean>
<!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!-- 自动扫描mapping.xml文件 -->
<property name="mapperLocations" value="classpath*:com/bolue/oa/mapper/*.xml"/>
</bean>
<!-- Dao接口所在包名,Spring会自动查找其下的类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.bolue.oa.dao"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>
<!-- 事务管理 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 声明式 Spring AOP的方式实现事务管理 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="query*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="select*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="find*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="save*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="create*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="add**" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="insert*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="update*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="modify*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="delete*" propagation="REQUIRED" rollback-for="Exception"/>
</tx:attributes>
</tx:advice>
<!-- 第一个*表示返回值,第二个*表示impl下class,第三个*表示方法名,(..)表示方法参数 -->
<aop:config>
<aop:advisor advice-ref="txAdvice" pointcut="execution(* com.bolue.oa.service.*.*(..))"/>
</aop:config>
</beans>

6、spring-mvc文件:
<?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"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-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/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.0.xsd">
<!-- 自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器 -->
<context:component-scan base-package="com.bolue.oa.controller"/>
<mvc:annotation-driven>
<mvc:message-converters>
<!-- 避免IE执行AJAX时, 返回JSON出现下载文件 -->
<bean id="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<!-- 文件上传 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- 默认编码 -->
<property name="defaultEncoding" value="utf-8" />
<!-- 文件大小最大值 -->
<property name="maxUploadSize" value="5000000"/>
<!-- 内存中的最大值 -->
<property name="maxInMemorySize" value="40960" />
</bean>
<!-- 定义跳转的文件的前后缀 ,视图模式配置-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 这里的配置我的理解是自动给后面action的方法return的字符串加上前缀和后缀,变成一个 可用的url地址 -->
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- 资源文件映射 -->
<mvc:resources location="/WEB-INF/assets/" mapping="/assets/**"/>
<mvc:resources location="/WEB-INF/js/" mapping="/js/**"/>
<mvc:resources location="/WEB-INF/css/" mapping="/css/**"/>
</beans>

7、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_2_5.xsd"
id="taotao" version="2.5">
<display-name>oa</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>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>
<!-- 加载spring容器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/spring-*.xml</param-value>
</context-param>
<!-- Spring监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 防止Spring内存溢出监听器 -->
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<!-- 解决Post乱码 -->
<filter>
<filter-name>CharacterEncodingFilter</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>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- SpringMVC的前端控制器 -->
<servlet>
<servlet-name>oa</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>oa</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
</web-app>

只要路径都写正确,应该不会有什么问题吧???

BUT!!!

登录时竟然给我报了一个invalid bound statement (not found)的异常

网上都说这是路径不对或mapper文件内容不对引起的,但我路径都是对的,mapper文件时自动生成的,不会错啊,那到底是哪错了...

坑爹的问题害我找了一天原因,原来是需要在pom.xml文件中配置resource,不然mapper.xml文件就会被漏掉!被漏掉!!被漏掉!!!

然后就在pom.xml的<build>中配置了resource:

<!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>

上面pom.xml中已经把这段代码写上去了,这里只是说明一下错误时因为它引起的。

然后,哈哈哈,bug终于被我消灭,怪兽终究还是打不过葫芦娃的
---------------------
作者:非阳
来源:CSDN
原文:https://blog.csdn.net/k469785635/article/details/77532512
版权声明:本文为博主原创文章,转载请附上博文链接!

04-22 10:48