一.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;

在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的依赖:

<dependency>
 <groupId>jstl</groupId>
 <artifactId>jstl</artifactId>
 <version>1.2</version>
 </dependency>

三.java.util.concurrent.ExecutionException:

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

可能原因是在web.xml中配置<servlet-mapping>时,  <url-pattern>属性配置错误
我写的是  <url-pattern>*.html/</url-pattern>,其实应该没有/,  改成这样就不报错了<url-pattern>*.html</url-pattern>

 

四.前端传参和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.<init>(MapperMethod.java:189)
    at org.apache.ibatis.binding.MapperMethod.<init>(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即可:

<build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
        </resource>
    </resources>
</build>

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

严重: 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:

<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>

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

 

 

 

 

7.jsp中调用

<li class="item-book" bookid="11078102">
     <div class="p-img">
         <a target="_blank" href="/item/${item.id }.html">
             <img width="160" height="160" data-img="1" data-lazyload="${item.images[0]}" />
         </a>
     </div>

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

public String[] getImages() {
         if(image!=null) {
             String[] images=image.split(",");
             return images;
         }
         return null;
     }

java 新的写法报错_java

 为什么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<javax.sql.DataSource>:
     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<javax.sql.DataSource>]Action:
 Update your application's configuration


 

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

<dependency>
	<groupId>log4j</groupId>
	<artifactId>log4j</artifactId>
	<version>1.2.16</version>
	<scope>compile</scope>
</dependency>