我是靠谱客的博主 细心睫毛,最近开发中收集的这篇文章主要介绍Maven+Spring+Mybatis搭建项目遇到的错误,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

(一)配置好tomcat服务器之后,发现没有run选项,或者说run没有变绿
出现此问题的一般原因是因为tomcat没有配置好,在下面的配置界面中不要点击Templates要点击**+**号,配置好之后会出现Tomcat 9.0.16(我使用的版本比较高,低版本应该更不容易出问题),如果没有出现这个选项则证明配置有问题,一定要点击+号!
在这里插入图片描述
(二)tomcat成功启动之后,却无法访问指定的.jsp界面,但是可以访问.html界面。server的console窗口报如下错误
`Caused by: org.apache.jasper.JasperException: org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.department_005flist_jsp
at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:604)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:422)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:712)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:459)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:384)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
at com.java.sm.controller.DepartmentController.list(DepartmentController.java:23)
… 30 more
Caused by: org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.department_005flist_jsp
at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:198)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:413)
… 43 more
Caused by: java.lang.ClassNotFoundException: org.apache.jsp.department_005flist_jsp
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:128)
at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:59)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:159)
at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:193)
… 44 more
06-Apr-2020 11:14:56.575 信息 [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployDescriptor Deploying deployment descriptor [C:UsersEstherLee.IntelliJIdea2019.3systemtomcatTomcat_9_0_16_smconfCatalinalocalhostROOT.xml]
06-Apr-2020 11:14:56.579 警告 [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployDescriptor The path attribute with value [/ROOT] in deployment descriptor [C:UsersEstherLee.IntelliJIdea2019.3systemtomcatTomcat_9_0_16_smconfCatalinalocalhostROOT.xml] has been ignored
06-Apr-2020 11:14:56.581 警告 [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployDescriptor A docBase [D:Javatomcatapache-tomcat-9.0.16webappsROOT] inside the host appBase has been specified, and will be ignored
06-Apr-2020 11:14:56.632 信息 [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployDescriptor Deployment of deployment descriptor [C:UsersEstherLee.IntelliJIdea2019.3systemtomcatTomcat_9_0_16_smconfCatalinalocalhostROOT.xml] has finished in [57] ms
06-Apr-2020 11:14:56.634 信息 [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployDirectory 把web 应用程序部署到目录 [D:Javatomcatapache-tomcat-9.0.16webappsmanager]
06-Apr-2020 11:14:56.704 信息 [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [D:Javatomcatapache-tomcat-9.0.16webappsmanager] has finished in [69] ms

因为在导入项目依赖的时候,我只按照慕课网上的教程导入了jstl一个依赖,所以一开始就怀疑这里有问题。于是查找了网上所给出的解决方案,需要在再导入一下三个依赖


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

        <!-- https://mvnrepository.com/artifact/javax.servlet.jsp.jstl/jstl-api -->
        <dependency>
            <groupId>javax.servlet.jsp.jstl</groupId>
            <artifactId>jstl-api</artifactId>
            <version>1.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.glassfish.web/jstl-impl -->
        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>jstl-impl</artifactId>
            <version>1.2</version>
        </dependency>


(三)修bug到现在还以为终于可以显示正确的界面了,谁知道,启动tomcat之后却发现访问的界面失去样式
由于我的.jsp文件是直接拷贝的慕课网的资料,所以一开始没有怀疑是.jsp文件的错,反而浪费了很多时间,例如清理chorm浏览器,始终找不到错误的来源,最后是将界面更改为其他界面,却发现样式没有丢失,于是怀疑是不是自己的.css的引入是不是有问题,在检查对比中发现一个致命但是非常愚蠢的错误。我写的是:

<link rel="stylesheet" type="text/css" href="css/reset.css"/>
    <link rel="stylesheet" type="text/css" href="css/common.css"/>
    <link rel="stylesheet" type="text/css" href="css/thems.css">

这样的写法我点击href选项发现可以跳转到指定文件夹所以觉得引用的没有问题,但实际上正确的写法是:

<link rel="stylesheet" type="text/css" href="../css/reset.css"/>
    <link rel="stylesheet" type="text/css" href="../css/common.css"/>
    <link rel="stylesheet" type="text/css" href="../css/thems.css">

.css文件是我在webapp文件夹下新建了一个css文件夹,然而引入的时候却忘记了需要加上"…/"真的蠢到极点。
(四)这个bug是始终贯穿在项目里的也就是,启动tomcat服务器,然而界面空白,server的console窗口报如下错误:Invalid bound statement (not found): com.java.sm.dao.DepartmentDao.selectAll

Caused by: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.java.sm.dao.DepartmentDao.selectAll
	at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:235)
	at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:53)
	at org.apache.ibatis.binding.MapperProxy.lambda$cachedInvoker$0(MapperProxy.java:107)
	at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705)
	at org.apache.ibatis.binding.MapperProxy.cachedInvoker(MapperProxy.java:94)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85)
	at com.sun.proxy.$Proxy20.selectAll(Unknown Source)
	at com.java.sm.service.impl.DepartmentServiceImpl.getAll(DepartmentServiceImpl.java:33)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:366)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:99)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
	at com.sun.proxy.$Proxy21.getAll(Unknown Source)
	at com.java.sm.controller.DepartmentController.list(DepartmentController.java:21)
	... 30 more
java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at com.java.sm.global.DispatcherServlet.service(DispatcherServlet.java:145)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at com.java.sm.global.EncodingFilter.doFilter(EncodingFilter.java:23)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.java.sm.dao.DepartmentDao.selectAll
	at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:235)
	at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:53)
	at org.apache.ibatis.binding.MapperProxy.lambda$cachedInvoker$0(MapperProxy.java:107)
	at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705)
	at org.apache.ibatis.binding.MapperProxy.cachedInvoker(MapperProxy.java:94)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85)
	at com.sun.proxy.$Proxy20.selectAll(Unknown Source)
	at com.java.sm.service.impl.DepartmentServiceImpl.getAll(DepartmentServiceImpl.java:33)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:366)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:99)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
	at com.sun.proxy.$Proxy21.getAll(Unknown Source)
	at com.java.sm.controller.DepartmentController.list(DepartmentController.java:21)
	... 30 more

其实这个错误是一直伴随着的,在刚看到这个问题的时候,提示说:selectAll方法有问题,我就在对应的XxxxController.java文件里先把方法给注掉了,然后就不在报这个错,转向报其他地方的错(233333)然后我是选择先把边边角角的小问题解决再来解决Mapper映射的问题
一般出现这个问题首先需要检查自己的mapper文件是否写对,这里不在赘述,我出现问题是一个新的问题,我是在spring.xml的配置文件中,没有扫描到mapper文件导致的。一开始我以为是

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.java.sm.dao"/>
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
    </bean>

这段代码里basePackage 的value配错了,所以无法扫描,所以浪费了很久时间更改这里希望找到mapper文件,但是这里其实没有配错,basePackage对应的value值应该是dao包下面的持久层接口。
真正错误的代码在下面

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="typeAliasesPackage" value="com.java.sm.entity"/>
        <!--<property name="mapperLocations" value="classpath:com.java.sm.dao/*.xml"/>-->
    </bean>

注销的那句代码一开始我没有写,所以无法知道mapperLocations才导致的无法映射,这段代码是必须的!正确的写法我也已经给出。
至此,我终于在浏览器中得到了想要的界面,成功的从数据库中取到了数据
在这里插入图片描述
这是小白第一次搭建Maven+Spring+Mybatis的项目,遇到了很多很多的错误,还有其他的bug并没有一一细说,希望自己以后不要写疯狂写bug了,不然真的哭了

最后

以上就是细心睫毛为你收集整理的Maven+Spring+Mybatis搭建项目遇到的错误的全部内容,希望文章能够帮你解决Maven+Spring+Mybatis搭建项目遇到的错误所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(41)

评论列表共有 0 条评论

立即
投稿
返回
顶部