java报错root cause_JavaWeb 报错记录

本文汇总了Spring框架中常见的问题及其解决办法,包括自动装配失败、JSP配置问题、前端与后端参数不匹配等,并提供了详细的排查和解决步骤。

开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

一.Could not autowire field

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pictureController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.service.PictureService com.controller.PictureController.pictureService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.service.PictureService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations:{@org.springframework.beans.factory.annotation.Autowired(required=true)}

在Controller中使用了AutoWired注解,注入service属性 pictureService,报错信息:找不到这个service,原因是在service层忘记加上@Service注解,加上即可

二.http://java.sun.com/jsp/jstl/core cannot be resolved

org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application

根本原因是web项目用了jsp,而jsp中使用了jstl,但是却没有引入jar包,jstl有1.1和1.2的版本,确定自己缺少的是什么版本,我是少了jstl1.2.jar

经测试下面两种方法都可以解决,我用了第二种

1.在WEB-INF/lib下拷贝一个jstl1.2.jar

2.在pom.xml中加入jstl的依赖:

jstl

jstl

1.2

三.java.util.concurrent.ExecutionException:

java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]

可能原因是在web.xml中配置时,  属性配置错误

我写的是  *.html/,其实应该没有/,  改成这样就不报错了*.html

四.前端传参和controller形参表不一致,导致null

严重: Servlet.service() for servlet [spring-manager] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause java.lang.NullPointerException

at com.net.controller.ConMakerController.createConMaker(ConMakerController.java:33)

前端传参:url:/create,参数:parentId

$.post("/create",{parentId:node.parentId},function(data){......});

java-Controller:

@RequestMapping("/create")

public boolean createConMaker(Long parentid) {

dosometing() .......

}

两个parentid要对应上,形参表里是小写的id,所以在这里接收到的parentid是null,故报错如上,改成parentId,大写的即可

五.406错误

406是HTTP协议状态码的一种,表示无法使用请求的特性来响应请求的网页。一般指客户端浏览器不接受所请求页面的MIME类型

1、json所依赖的jar包不存在。一般是jackson

2、spring和jackson版本对不上:

如果是使用的spring 4.0.*的话,可以引入jackson1.9.*的包

如果是使用的spring4.1.*的话,可以引入jackson2.7.*的。

3、请求的后缀是.html的,返回的格式是json的

如果是以html为后缀的url发起请求,然后@ResponseBody返回时转换成json,就会报406.

六.配置文件没有复制到target/classes文件加下

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): cn.kevin.search.mapper.ItemMapper.getItemList

at org.apache.ibatis.binding.MapperMethod$SqlCommand.(MapperMethod.java:189)

at org.apache.ibatis.binding.MapperMethod.(MapperMethod.java:43)

at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:58)

这个报错是由于,itemMapper.xml在src/main/java目录下,而Eclipse在build的时候,默认只会把src/main/resources下面的配置文件复制到classes下,而src/main/java目录下则只会复制.java文件生成的.class文件。所以漏掉了在src/main/java目录下的itemMapper.xml文件,所以报错。

解决方法就在pom.xml下加入bulid即可:

src/main/java

**/*.properties

**/*.xml

false

修改后在运行,还是报错:

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener

org.springframework.beans.factory.BeanDefinitionStoreException: Could not resolve bean definition resource pattern [classpath:spring/applicationContext*.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring/] cannot be resolved to URL because it does not exist   at  org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:229)

找不到spring/applicationContext*.xml 配置文件。。

查看target/classes目录,发现上面的itemMapper.xml是有了,但是src/main/resources下面的配置文件却没有了。。可能是由于配置了上面的build节点,导致只复制了src/main/java下的配置文件,既然这样,那就在修改下pom.xml:

src/main/java

**/*.properties

**/*.xml

false

src/main/resources

**/*.properties

**/*.xml

false

在上面的基础上,添加上src/main/resources的配置

7.jsp中调用

            

jsp中item.images[0] 为什么能调用到java,Item实体类中的

public String[] getImages() {

if(image!=null) {

String[] images=image.split(",");

return images;

}

return null;

}

1f1ec7ff586ab13d6dab179544e3b531.png

为什么model设置model.addAttribute("query", “苹果CR”);,能直接返回jsp,然后在jsp中能显示相关的信息苹果CR

8.SpringBoot2.1.5创建项目

配置完application.yml后运行不起来报错:

Failed to bind properties under 'spring.datasource.type' to java.lang.Class:

Property: spring.datasource.type

Value: org.apache.tomcat.jdbc.pool.DataSource

Origin: class path resource [application.properties]:5:24

Reason: No converter found capable of converting from type [java.lang.String] to type [java.lang.Class]

Action:

Update your application's configuration

解决:在pom.xml中加入log4j的依赖

log4j

log4j

1.2.16

compile

开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值