引起:java.lang.IllegalArgumentException:属性'driverClassName'不能为空
Posted
技术标签:
【中文标题】引起:java.lang.IllegalArgumentException:属性\'driverClassName\'不能为空【英文标题】:Caused by: java.lang.IllegalArgumentException: Property 'driverClassName' must not be empty引起:java.lang.IllegalArgumentException:属性'driverClassName'不能为空 【发布时间】:2020-06-09 09:02:15 【问题描述】:在我在这里分享的代码Exception in thread "restartedMain" java.lang.reflect.InvocationTargetException Caused by: java.lang.NullPointerException 中出现新错误。你能帮我解决这个问题吗?
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'springLogging3Application': Unsatisfied dependency expressed through field 'factory'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'factory' defined in com.spring.main.SpringLogging3Application: Unsatisfied dependency expressed through method 'getSessionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'datasource' defined in com.spring.main.SpringLogging3Application: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Circular reference involving containing bean 'springLogging3Application' - consider declaring the factory method as static for independence from its containing instance. Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalArgumentException: Property 'driverClassName' must not be empty
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:598) ~[spring-beans-5.1.15.RELEASE.jar:5.1.15.RELEASE]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Circular reference involving containing bean 'springLogging3Application' - consider declaring the factory method as static for independence from its containing instance. Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalArgumentException: Property 'driverClassName' must not be empty
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.1.15.RELEASE.jar:5.1.15.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ~[spring-beans-5.1.15.RELEASE.jar:5.1.15.RELEASE]
... 51 common frames omitted
Caused by: java.lang.IllegalArgumentException: Property 'driverClassName' must not be empty
at org.springframework.util.Assert.hasText(Assert.java:284) ~[spring-core-5.1.15.RELEASE.jar:5.1.15.RELEASE]
application.properties
server.port=6565
db.driver:oracle.jdbc.driver.OracleDriver
db.url:jdbc:oracle:thin:@localhost:1521:xe
db.username:xxxx
db.password:xxxx
hibarenate.dialect:org.hibernate.dialect.OracleDialect
hibarenate.show_sql:true
hibarenate.hbm2ddl.auto:update
entitymanager.packagesToScan:com.spring.main
更新了一个:
server.port=6565
db.driver=oracle.jdbc.driver.OracleDriver
db.url=jdbc:oracle:thin:@localhost:1521:xe
db.username=xxxx
db.password=xxxx
hibarenate.dialect=org.hibernate.dialect.OracleDialect
hibarenate.show_sql=true
hibarenate.hbm2ddl.auto=update
entitymanager.packagesToScan=com.spring.main
【问题讨论】:
你能分享文件 application.properties 或 application.yml 吗? @Fatih 我已添加。 您使用的是弹簧型材吗? @Fatih 不,我没有使用任何个人资料。 你的应用程序文件乱了,属性用等号分隔key=value
对
【参考方案1】:
尝试以下方法:
不要在 application.properties 文件中混合使用“=”和“:”分隔符 记录“db.driver”属性,好像是空的问候。
【讨论】:
请更新您尝试过的新应用程序。 @silentsudo 添加。更新了 application.properties 这不是我的问题的解决方案。请不要标记它。【参考方案2】:请分享并检查您的 xyz-servlet.xml 配置文件,您在其中定义了 spring spring boot 和 hibernate 信息。在看到您的错误后,我知道这是您的 xml 文件中的 hibernate 异常,请检查您是否已定义或不是 DriverClassName 详情见下面的例子
看看这个DB有四个属性driverClassName、url、username和password
<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" name="dataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>**check this property whether you have define or not if not then define it corresponding DB driver name as i have defined my driver details**
<property name="url" value="jdbc:mysql://localhost:3306/hibernatedb"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</bean>
【讨论】:
我没有使用 XML 进行配置。我用注释做到了这一点,并将我的属性文件粘贴在上面。完整代码请查看***.com/questions/62238830/…以上是关于引起:java.lang.IllegalArgumentException:属性'driverClassName'不能为空的主要内容,如果未能解决你的问题,请参考以下文章