spring常见错误总结

在学习spring过程中遇见了种种不同的异常错误,这里做了一下总结,希望遇见类似错误的同学们共勉一下。

1. 错误一

Error creating bean with name 'helloServiceImpl' defined in class path resource [spring-service.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'helloDao' of bean class [www.csdn.spring.service.impl.HelloServiceImpl]: Bean property 'helloDao' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'helloDao' of bean class

这类错误是:一般都是创建了一个dao的spring文件比如spring-dao有创建了一个service的spring文件,在spring-service.xml中引用dao的中定义的id名,导致的错误,疏忽是:写service实现类的时候忘记了写对应dao的setter方法,即所谓的依赖注入

比如:

private HelloDao helloDao;

//set依赖注入很重要,不写会报错,不能读写helloDao这一属性

publicvoid
setHelloDao(HelloDao helloDao) {

System.out

.println("控制反转:应用程序本身不在负责创建helloDao对象,而是由spring容器负责创建、管理、维护,这样控制权转移,称为反转。"

+
"可以通过依赖注入方式注入该HelloDao对象");

this.helloDao
= helloDao;

}

2.
错误二

Configuration
problem: Failed to import bean definitions from relative location
[spring-dao.xml]Offending resource: class path resource [spring.xml];
nested exception is
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:
Line 9 in XML document from class path resource [spring-dao.xml] is
invalid; nested exception is org.xml.sax.SAXParseException: Open
quote is expected for attribute "{1}" associated with an
element type "scope".

Caused
by:
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:
Line 9 in XML document from class path resource [spring-dao.xml] is
invalid; nested exception is org.xml.sax.SAXParseException: Open
quote is expected for

Caused
by: org.xml.sax.SAXParseException: Open quote is expected for
attribute "{1}" associated with an element type "scope".

这种错误是马虎的错误,在对应的spring的配置文件中,bean标签的scope属性忘了加引号,在配置文件中国不会报错,但是在运行的时候就会出这样的错,一般导致错误的原因是复制的时候疏忽了引号,直接将原来的引号覆盖了,导致了最后该属性没有引号。

<bean
id="helloDaoImpl"
class="www.csdn.spring.dao.impl.HelloDaoImpl"

scope="prototype"></bean>

错误的写成:

bean
id="helloDaoImpl"
class="www.csdn.spring.dao.impl.HelloDaoImpl"

scope=prototype></bean>

3.
错误三

No
bean named 'helloServiceImp' is defined

at
org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition

这种报错但是没有Caused
by语句的错误一般都是使用的时候单词写错了,这里写错的地方是在java类中,类中引用id的时候写错了单词;比如这里的错,注意下面的红色文字:

HelloService
helloService2 = (HelloService)
context.getBean("helloServiceImp",HelloServiceImpl.class);

<bean
id="helloServiceImpl"
class="www.csdn.spring.service.impl.HelloServiceImpl"
scope="singleton" lazy-init="false">

<property
name="helloDao" ref="helloDaoImpl"/>

</bean>

眼尖的哥们估计都看出来了这两个单词写的不一样,获取bean的方法中引用的id少写了一个“i”,导致spring容器在读取的时候不能识别。以后注意细心就好。

4.
错误四

Error
creating bean with name 'helloServiceImpl' defined in class path
resource [spring-service.xml]: Cannot resolve reference to bean
'helloDaoImp' while setting bean property 'helloDao'; nested
exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
bean named 'helloDaoImp' is defined

Caused
by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
No bean named 'helloDaoImp' is defined

at
org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition

这种也是单词写错的情况,与上面不同的是这种情况给出了Caused
by语句,让你更清楚错误发生的原因,英文还差不多的哥们或者有一定编程经验的人员一看Caused
by语句就应该能判断出什么错误;这里错误原因明显才、指出每一个名字为'helloDaoImp'的bean,或名字为'helloDaoImp'的bean未定义,这种错也好好找,一般都是互相引用的spring配置文件马虎出的错,下面一个例子说明:比如spring-service.xml引用spring-dao的时候,还是如上面说的一样,重点再红色字体

Service配置文件中这么写:

<bean
id="helloServiceImpl"
class="www.csdn.spring.service.impl.HelloServiceImpl"
scope="singleton" lazy-init="false">

<property
name="helloDao" ref="helloDaoImp"/>

</bean>

但是dao配置文件中却这么写:

bean
id="helloDaoImpl"
class="www.csdn.spring.dao.impl.HelloDaoImpl"

scope="prototype"></bean>

写到这大家就清楚了吧,与上一个错误基本上一样,都是单词写错的错误,只不过不同的是上一个错误是在java类中引用id的时候写错单词出的错,而这一个错误是在spring配置文件中国引用id出的错,万变不离其宗,错误的额原因都是单词写错,今后细心即可。

5.
错误五

Cannot
find class [www.csdn.spring.dao.imp.HelloDaoImpl] for bean with name
'helloDaoImpl' defined in ServletContext resource
[/WEB-INF/applicationContext.xml]; nested exception is
java.lang.ClassNotFoundException:www.csdn.spring.dao.imp.HelloDaoImpl

Caused
by: java.lang.ClassNotFoundException:
www.csdn.spring.dao.HelloDaoImpl

错误原因:倒错包了,我的web项目HelloDaoImpl在dao.impl包下而不是dao包下。所以包这样的错,看一下spring配置文具店额classes标签的值导入的类包名是否正确

6.
错误六

org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'employeeBean' defined in class path
resource [spring-constructor.xml]: Unsatisfied dependency expressed
through constructor argument with index 2 of type [double]: Ambiguous
constructor argument types - did you specify the correct bean
references as constructor arguments?

错误原因:bean实例类中的属性类型与spring配置文件中的构造器属性类型不对应所导致,这种情况多出在使用类型指定构造器参数;比如:

类中属性如下,重点注意红色部分:

private
String name;

private
String sex;

private
doublesalary;

spring配置文件中的构造器标签

<constructor-arg
type="java.lang.String" value="杨凯"
/>

<constructor-arg
type="java.lang.String" value="男"
/>

<constructor-arg
type=" java.lang.Double" value="5000.00" />

这种错误是因为构造器中的type属性不会自动对应拆箱装箱属性类型,简单点说就是类中使用的是基本数据类型,配置文件中对应的type属性值就要是基本数据类型;类中使用的是类类型,配置文件中对应的type属性值就要是包名加上类类型;

还有一种原因就是不对应的原因,constructor-arg直接写错了,比如:private
doublesalary;对应了<constructor-arg
type=" Double" value="5000.00" />

或者顺序不对的情况下回出现赋值错误,比如同时存在两个相同类型的属性,name应该为“杨凯”,如果sex在配置文件的位置与name的颠倒了,会出现name=“男”的情况

7.
错误七

org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'memberBean' defined in class path
resource [spring-construtor.xml]: Initialization of bean failed;
nested exception is
org.springframework.beans.ConversionNotSupportedException: Failed to
convert property value of type 'java.lang.String' to required type
'www.csdn.spring.constructor.Member' for property 'member'; nested
exception is java.lang.IllegalStateException: Cannot convert value of
type [java.lang.String] to required type
[www.csdn.spring.constructor.Member] for property 'member': no
matching editors or conversion strategy found

Caused
by: org.springframework.beans.ConversionNotSupportedException: Failed
to convert property value of type 'java.lang.String' to required type
'www.csdn.spring.constructor.Member' for property 'member'; nested
exception is java.lang.IllegalStateException: Cannot convert value of
type [java.lang.String] to required type
[www.csdn.spring.constructor.Member] for property 'member': no
matching editors or conversion strategy found

错误原因:这种情况是一个bean实例引用另一个bean实例对象,而引用的那个bean实例对象为空,但是在改bean实例的配置文件中又错误指明空值。举个例子说明:

<bean
id="memberBean"
class="www.csdn.spring.constructor.MemberBean">

<!--
value="null" 这里给value赋的是一个空字符串,而不是一个null空值-->

<property
name="name" value="null"/>

<property
name="member">

<null/>

</property>

</bean>

关键看红色部分,红色部分是正确的写法,这样写引用空值对象才不会报错,但是如果你像上面引用nam属性那样指明value=“null”就会出现改错。

8.
错误八

错误一:

org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Bean name 'deptBean' is already used in this
<beans> element

Offending
resource: class path resource [spring-byType.xml]

错误二:

org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'empBean' defined in class path
resource [spring-byType.xml]: Unsatisfied dependency expressed
through bean property 'deptBean': : No qualifying bean of type
[www.csdn.spring.autowire.DeptBean] is defined: expected single
matching bean but found 2: deptBean,deptBean1; nested exception is
org.springframework.beans.factory.NoUniqueBeanDefinitionException: No
qualifying bean of type [www.csdn.spring.autowire.DeptBean] is
defined: expected single matching bean but found 2:
deptBean,deptBean1

Caused
by:
org.springframework.beans.factory.NoUniqueBeanDefinitionException: No
qualifying bean of type [www.csdn.spring.autowire.DeptBean] is
defined: expected single matching bean but found 2:
deptBean,deptBean1

这两种错误原因:都是spring配置文件中自动装配按byType时出的问题,配置文件,
红色部分为错误的解释和导致错误的原因如下:

<bean
id="compBean" class="www.csdn.spring.autowire.CompBean">

<property
name="name" value="DELL"/>

</bean>

<bean
id="deptBean" class="www.csdn.spring.autowire.DeptBean">

<property
name="name" value="销售部门"/>

</bean>

<!--

这里只能出现一个deotBean,id名不一样但是类型一样,都是deptBean实体的;id="deptBean"或同类型的不同id都会抛异常

<bean
id="deptBean1" class="www.csdn.spring.autowire.DeptBean">

<property
name="name" value="销售部门"/>

</bean>
-->

<!--
使用autoWrie自动装配,改属性值byType;

按类型自动装配,前提是同一个类型的只能有一个-->

<bean
id="empBean" class="www.csdn.spring.autowire.EmpBean"
autowire="byType">

<property
name="name" value="杨凯"/>

<!--
<property name="comp" ref="compBean"/>

<property
name="dept" ref="deptBean"/> -->

</bean>

9.
错误九

org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'empBean' defined in class path
resource [spring-byConstructor.xml]: Unsatisfied dependency expressed
through constructor argument with index 0 of type
[www.csdn.spring.autowire.DeptBean]: : No qualifying bean of type
[www.csdn.spring.autowire.DeptBean] is defined: expected single
matching bean but found 2: deptBean1,deptBean2; nested exception is
org.springframework.beans.factory.NoUniqueBeanDefinitionException: No
qualifying bean of type [www.csdn.spring.autowire.DeptBean] is
defined: expected single matching bean but found 2:
deptBean1,deptBean2

at
org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray

Caused
by:
org.springframework.beans.factory.NoUniqueBeanDefinitionException: No
qualifying bean of type [www.csdn.spring.autowire.DeptBean] is
defined: expected single matching bean but found 2:
deptBean1,deptBean2

错误原因:
spring配置文件中自动装配按constructor时出的问题,配置文件,
红色部分为错误的解释和导致错误的原因如下:

<!--
在spring3.2以上版本中:使用构造器自动装配时,如果有一个id与bean实例中的属性名相同的配置bean存在,虽然构造器自动装配是按类型自动装配的,

但是即使有多个相同类型的bean存在也不受影响;受影响的情况是:没有与bean实例中的属性名相同的配置bean存在,

又有多个相同类型的bean配置,就会抛异常-->

<bean
id="deptBean" class="www.csdn.spring.autowire.DeptBean">

<property
name="name" value="销售部门"/>

</bean>

<bean
id="deptBean1" class="www.csdn.spring.autowire.DeptBean">

<property
name="name" value="销售部门"/>

</bean>

<bean
id="deptBean2" class="www.csdn.spring.autowire.DeptBean">

<property
name="name" value="销售部门"/>

</bean>

<!--
使用autoWrie自动装配,改属性值constructor;构造器自动装配就是按类型自动装配

beam实例中必须结合构造器使用,如果没有构造器自动装配后注入不进去值,取出为空值-->

<bean
id="empBean" class="www.csdn.spring.autowire.EmpBean"
autowire="constructor">

<property
name="name" value="杨凯"/>

<!--
<property name="comp" ref="compBean"/>

<property
name="dept" ref="deptBean"/> -->

</bean>

10.
错误十

org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Unexpected failure

during
bean definition parsing

Offending
resource: class path resource [spring-collection.xml]

Bean
'collectionBean'; nested exception is
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:

Configuration
problem: <property> element for property 'users' must specify a
ref or value

Offending
resource: class path resource [spring-collection.xml]

Bean
'collectionBean'

->
Property 'users'

Caused
by:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: <property>

element
for property 'users' must specify a ref or value

Offending
resource: class path resource [spring-collection.xml]

Bean
'collectionBean'

->
Property 'users'

乍一看,有些许没有头脑,但是放下心仔细看看,提示说什么users属性怎么怎么滴;还有一点提示就是说是spring-collection.xml配置文件中的错误,这就好找,找到改配置中有关users的地方,

<bean
id="u1" class="www.csdn.spring.collection.set.User">

<property
name="name" value="杨凯"
/>

<property
name="age" value="22" />

</bean>

。。。。。

这样的代码肯定不会出错了,如果是这里的错报的就不是这个错了,可能就是第一条或第二条错了;再找下一块有users的地方,找到了这里:

<!--
list集合-->

<property
name="users">

<!--
<array>

<ref
bean="u1" />

<ref
bean="u2" />

<ref
bean="u3" />

</array>
-->

<!--
<list>

<ref
bean="u1"/>

<ref
bean="u2"/>

<ref
bean="u3"/>

</list>
-->

<!--
还可以通过spring自带的sehema约束中的util工具约束的list集合遍历-->

<util:list>

<ref
bean="u1" />

<ref
bean="u2" />

<ref
bean="u3" />

</util:list>

</property>

仔细一看真是这里的错,红色部分最开始忘了写,注释掉了上面的list注入值的方式,后面的uti标签注入值有没有写,这是在测试类中取值遍历的时候就会遍历一个空的users,这是因为是没有注入值的错,所以没有报空指针的错,报的是这种莫名其妙的错。

11.
错误十一

org.springframework.beans.factory.BeanNotOfRequiredTypeException:
Bean named 'proxyFactoryBean' must be of type
[www.csdn.spring.advice.SayServiceImpls], but was actually of type
[$Proxy4]

这种错误一般出在aop面向切面的编程中,spring面向切面的代理有两种,一种是jdk动态代理,一种是cglib代理;这是你在使用的的使用如果混合时候就会出现上面的错;这两种代理的区别是前者是接口代理,就是返回一个接口类型对象,而后者是类代理,不能返回接口类型对象只能返回类类型对象,如果返回接口了同样会出这样的错。

还有可能出错的地方就是对应的spring配置文件,这

里是最容易马虎出错的地方,仔细检查一下的你的目标对象,比如:<!--
目标对象-->

<property
name="target">

<ref
bean="sayServiceImpls"/>

</property>

这里在引用bean的时候可能引入错误,可能会引入jdk动态代理的目标类,也有可能你的目标类中实现了某些接口,不符合cglib代理的理念;还有可能马虎出错的地方:

<!--
真实主题目标对象-->

<bean
id="sayServiceImpls"
class="www.csdn.spring.advice.SayServiceImpls"></bean>

真实对象的id和class属性设置错误的时候也会出错。

12.
错误十二

org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'proxyFactoryBean' defined in class
path resource [spring-advice.xml]: Error setting property values;
nested exception is
org.springframework.beans.PropertyBatchUpdateException; nested
PropertyAccessExceptions (1) are:

PropertyAccessException
1: org.springframework.beans.MethodInvocationException: Property
'proxyInterfaces' threw exception; nested exception is
java.lang.IllegalArgumentException:
[www.csdn.spring.proxy.advice.SayServiceImpl] is not an interface

Caused
by: org.springframework.beans.PropertyBatchUpdateException; nested
PropertyAccessExceptions (1) are:PropertyAccessException 1:
org.springframework.beans.MethodInvocationException: Property
'proxyInterfaces' threw exception; nested exception is
java.lang.IllegalArgumentException:
[www.csdn.spring.proxy.advice.SayServiceImpl] is not an interface

这个问题很好解决,最关键的问题出在红色部分,原因是在spring相关配置文件中设置抽象主题的时候,既然是抽象主题就应该设置成接口,而不应该是实现类。比如下面的代码,注意红色部分:

<!--抽象主题实现接口-->

<property
name="proxyInterfaces">

<array>

<value>www.csdn.spring.proxy.advice.SayServiceImpl</value>

</array>

</property>

正确的写法应该是:

<!--抽象主题实现接口-->

<property
name="proxyInterfaces">

<array>

<value>www.csdn.spring.proxy.advice.SayService</value>

</array>

</property>

13.
错误十三

org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'proxyFactoryBean': FactoryBean threw
exception on object creation; nested exception is
org.springframework.aop.framework.AopConfigException: Unknown advisor
type class www.csdn.spring.proxy.advice.AuditableImpl; Can only
include Advisor or Advice type beans in interceptorNames chain except
for last entry,which may also be target or TargetSource; nested
exception is
org.springframework.aop.framework.adapter.UnknownAdviceTypeException:
Advice object [www.csdn.spring.proxy.advice.AuditableImpl@1f758500]
is neither a supported subinterface of [org.aopalliance.aop.Advice]
nor an [org.springframework.aop.Advisor]

Caused
by: org.springframework.aop.framework.AopConfigException: Unknown
advisor type class www.csdn.spring.proxy.advice.AuditableImpl; Can
only include Advisor or Advice type beans in interceptorNames chain
except for last entry,which may also be target or TargetSource;
nested exception is
org.springframework.aop.framework.adapter.UnknownAdviceTypeException:
Advice object [www.csdn.spring.proxy.advice.AuditableImpl@1f758500]
is neither a supported subinterface of [org.aopalliance.aop.Advice]
nor an [org.springframework.aop.Advisor]

这个错误即红色部分提示的错误,不知道advice类型的异常,说白了就是编写的spring通知的错误,这种错误比较常见,也是出于马虎的错误,比如前者通知、后置通知、环绕通知、异常通知、引入通知等这几个通知中的任何一个通知类忘了写继承的父类;以下列出这几个通知的类编写所继承的类:

前置通知:

public
class BeforeAdvice implements MethodBeforeAdvice

后置通知:

public
class AfterAdvice implements AfterReturningAdvice

环绕通知:

public
class AroundAdvice implements MethodInterceptor

异常通知:

public
class ThrowAdvice implements ThrowsAdvice

引入通知:

public
class AuditableImpl extends DelegatingIntroductionInterceptor
implements Auditable

14.
错误十四

java.lang.ClassCastException:

$Proxy10
cannot be cast to www.csdn.spring.proxy.advice.Auditable

java.lang.ClassCastException:

$Proxy11
cannot be cast to www.csdn.spring.proxy.advice.Auditable

像以上这个出现$ProxyXX
cannot be cast to
www.csdn.spring.proxy.advice.Auditable;什么代理不能强转成某一个类型的错误,一般都是在使用JDK动态代理或cglib代理的时候出现的错误,错误原因有:

1).JDK动态代理与cglib代理混淆,比如使用cglib代理时不能实现接口,你可能在使用的时候使用了cglib代理,但是却实现了接口,如果你在spring配置文件中使用aspectjs来进行通知,又想使用cglib接口那么你需要做的是目标类不实现接口,spring配置文件中配置aop的时候加上下面红色部分。

<aop:aspectj-autoproxyproxy-target-class="true"/>

2)同样是使用aspectjs通知的时候,尤其是使用引入通知的时候,一定不要忘了让引用通知的业务类加上注解@Aspect;还要注意的是你使用的引入目标类和其实现接口的类路径一定要正确,我这里就范了一个小错误,到错包的错:

package
www.csdn.spring.proxy.advice.aspectjs;

import
org.aspectj.lang.annotation.Aspect;

import
org.aspectj.lang.annotation.DeclareParents;

@Aspect

publicclass
AuditableService {

@DeclareParents(value="*..*Service*",
defaultImpl = AuditableImpl.class)

public
Auditable auditable;

}

我在使用Auditable接口的时候倒错了包,这里其实类都在同一包下,根本不用倒包,但是我从上一个包中复制代码的时候自动给我引入了上一个包的Auditable类;以后一定要注意了

15.
错误十五

org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: <aspect> tag needs aspect bean reference
via 'ref' attribute when declaring advices.

Offending
resource: file
[F:\csdn-study\MyWorkspace\springHelloJava\bin\spring-pojoXmlAspectjs.xml]

Aspect:
ref=''

这个错误顾名思义,这里已经提示的很清了,这里列出这个错误是对那些对pojo-xml配置通知不太熟悉的同学而言;这个错误就是在对应的spring配置文件中使用aop切面的时候忘写了一个ref熟悉的错,具体案例代码如下,注意下面的红色部分,错误就出在红色部分忘了写ref="adviceService":

<!--
使用pojo-xml
aspectjs配置自动代理-->

<aop:config>

<!--
配置切面-->

<aop:aspect
ref="adviceService">

<!--
引入通知-->

<aop:declare-parents
types-matching="*..*Service*"

implement-interface="www.csdn.spring.proxy.advice.aspectjs.pojoxml.Auditable"

default-impl="www.csdn.spring.proxy.advice.aspectjs.pojoxml.AuditableImpl"
/>

<!--
切面切入的位置切入点,可以同时写多个不同的切入点-->

<aop:pointcut
expression="execution(* www.csdn..UserServiceImpl.save(..))"

id="myPcut"
/>

<aop:pointcut
expression="execution(* www.csdn..UserServiceImpl.update(..))"

id="myPcuts"
/>

<!--织入通知method:指明方法;
pointcut-ref引入切入点-->

<aop:before
method="beforeMethod" pointcut-ref="myPcut" />

<aop:after
method="afterMethod" pointcut-ref="myPcut" />

<aop:around
method="aroundMethod" pointcut-ref="myPcuts" />

</aop:aspect>

</aop:config>

16.
错误十六

org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'deptDaoImpl' defined in class path
resource [spring-dao.xml]: Could not resolve matching constructor
(hint: specify index/type/name arguments for simple parameters to
avoid type ambiguities)

关键是蓝色部分,蓝色部分已经给出了提示:不匹配的构造器,这种错误出在spring配置中,使用namedParameterJdbcTemplate时出的错,错误出在下面:

<bean
id="namedParameterJdbcTemplate"

class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">

<property
name="namedParameterJdbcTemplate"
ref="namedParameterJdbcTemplate" />

</bean>

正确写法:

<bean
id="deptDaoImpl" class="www.csdn.spring.jdbc.DeptDaoImpl">

<property
name="namedParameterJdbcTemplate"
ref="namedParameterJdbcTemplate" />

</bean>

由于对该类不理解或者复制时容易出这样的错误

17.
错误十七

org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'localSessionFactoryBean' defined in
class path resource [spring-hibernate.xml]: Invocation of init method
failed; nested exception is org.hibernate.HibernateException:
'hibernate.dialect' must be set when no Connection available

Caused
by: org.hibernate.HibernateException: 'hibernate.dialect' must be set
when no Connection available

这里根据提示说错误的原因是当数据库不能连接的时候,需要配置hibernate.dialect'就是hibernate配置的方言,原因出在驱动类的配置,比如:properties文件中的:hibernate.driverClassName=oracle.jdbc.driver.OracleDriver

这里如果写错了就会出现不能连接的情况,驱动的名字一定要正确,配置文件中的其他属性也一定要正确,据我本人测试如果在改配置文件中直接写的driverClassName=oracle.jdbc.driver.OracleDriver

在spring配置文件这样取值时:<property
name="driverClassName" value="${driverClassName}"
/>就会错误,但是如果这样写就对:<property
name="driverClassName" value="${hibernate.driverClassName}"
/>

18.
错误十八

java.lang.IllegalArgumentException:
node to traverse cannot be null!

解决方法:通常此类错误都是由于HQL语句写的不正确,例如from写成了form,或者set
A = 1 and B = 2,其中set不同字段用逗号","分离而不是用and.总之仔细检查HQL语句,看看有没有语法错误即可.

spring cuowu的更多相关文章

  1. Spring Boot 整合Spring Data以及rabbitmq,thymeleaf,向qq邮箱发送信息

    首先得将自己的qq开启qq邮箱的POP3/SMTP服务 说明: p,e为路由key. 用户系统完成登录的时候,将{手机号-时间-IP}保存到队列Phone-queue中,msg-sys系统获得消息打印 ...

  2. 基于spring注解AOP的异常处理

    一.前言 项目刚刚开发的时候,并没有做好充足的准备.开发到一定程度的时候才会想到还有一些问题没有解决.就比如今天我要说的一个问题:异常的处理.写程序的时候一般都会通过try...catch...fin ...

  3. 玩转spring boot——快速开始

    开发环境: IED环境:Eclipse JDK版本:1.8 maven版本:3.3.9 一.创建一个spring boot的mcv web应用程序 打开Eclipse,新建Maven项目 选择quic ...

  4. Spring基于AOP的事务管理

                                  Spring基于AOP的事务管理 事务 事务是一系列动作,这一系列动作综合在一起组成一个完整的工作单元,如果有任何一个动作执行失败,那么事务 ...

  5. [Spring]IoC容器之进击的注解

    先啰嗦两句: 第一次在博客园使用markdown编辑,感觉渲染样式差强人意,还是github的样式比较顺眼. 概述 Spring2.5 引入了注解. 于是,一个问题产生了:使用注解方式注入 JavaB ...

  6. 学习AOP之透过Spring的Ioc理解Advisor

    花了几天时间来学习Spring,突然明白一个问题,就是看书不能让人理解Spring,一方面要结合使用场景,另一方面要阅读源代码,这种方式理解起来事半功倍.那看书有什么用呢?主要还是扩展视野,毕竟书是别 ...

  7. 学习AOP之深入一点Spring Aop

    上一篇<学习AOP之认识一下SpringAOP>中大体的了解了代理.动态代理及SpringAop的知识.因为写的篇幅长了点所以还是再写一篇吧.接下来开始深入一点Spring aop的一些实 ...

  8. 学习AOP之认识一下Spring AOP

    心碎之事 要说知道AOP这个词倒是很久很久以前了,但是直到今天我也不敢说非常的理解它,其中的各种概念即抽象又太拗口. 在几次面试中都被问及AOP,但是真的没有答上来,或者都在面上,这给面试官的感觉就是 ...

  9. 为什么做java的web开发我们会使用struts2,springMVC和spring这样的框架?

    今年我一直在思考web开发里的前后端分离的问题,到了现在也颇有点心得了,随着这个问题的深入,再加以现在公司很多web项目的控制层的技术框架由struts2迁移到springMVC,我突然有了一个新的疑 ...

随机推荐

  1. C/C++中的虚析构函数和私有析构函数的使用

    代码: #include <iostream> using namespace std; class A{ public: A(){ cout<<"construct ...

  2. RCP打包出来 运行 出现 JVM terminated.exit code = 13

    在建立PM.product,即打包时,没有添加相应的插件,导致无法运行

  3. JS小数位保留两位小数--toFixed()

    parseInt,parseFloat,parseDouble在JS中是将值转换成相应的类型: 你必须要这样,才能实现: <script>         alert(parseFloat ...

  4. 1169 二叉树遍历(XCOJ DFS)

    给出一棵二叉树的中序与后序排列.求出它的先序排列.(约定树结点用不同的大写字母表示,长度≤8). 样例输入 BADC BDCA 样例输出 ABCD #include <iostream> ...

  5. [OpenJudge] 百练2754 八皇后

    八皇后 Description 会下国际象棋的人都很清楚:皇后可以在横.竖.斜线上不限步数地吃掉其他棋子.如何将8个皇后放在棋盘上(有8 * 8个方格),使它们谁也不能被吃掉!这就是著名的八皇后问题. ...

  6. zoj 3772 Calculate the Function

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5235 这道题需要构造矩阵:F(X)=F(X-1)+F(X-2)*A(X)转化为 ...

  7. 【转】用Device tree overlay掌控Beaglebone Black的硬件资源

    原文网址:https://techfantastic.wordpress.com/2013/11/15/beaglebone-black-device-tree-overlay/ 经过一晚上的Goog ...

  8. ofbiz ins

  9. DBA 经典面试题(3)

    这里的回答并不是十分全面,这些问题可以通过多个角度来进行解释,也许你不必在面试过程中给出完全详尽的答案,只需要通过你的解答使面试考官了解你对ORACLE概念的熟悉程度.   1.解释冷备份和热备份的不 ...

  10. [Oracle] 参数修改小结

    v$parameter Oracle参数的修改比较复杂,有些参数是可以在session级别修改,有些则必须在system级别修改,有些参数修改后马上生效(不需要重启),有些参数则必须重启才能生效,那么 ...