SSM报错“Invalid property ' username' of bean class [org.apache.commons.dbcp2.BasicDataSource]”_二木成林的博客-程序员宅基地

技术标签: 异常处理  SSM  异常  

错误

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property ' username' of bean class [org.apache.commons.dbcp2.BasicDataSource]: Bean property ' username' is not writable or has an invalid setter method. Did you mean 'username'?
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1493)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197)
25-Jan-2020 18:43:05.432 涓ラ噸 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
25-Jan-2020 18:43:05.433 涓ラ噸 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal Context [] startup failed due to previous errors
	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4685)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5146)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:717)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
	at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1728)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:289)
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
	at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:456)
	at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:405)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:289)
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
	at com.sun.jmx.remote.security.MBeanServerAccessController.invoke(MBeanServerAccessController.java:468)
	at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468)
	at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
	at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)
	at java.security.AccessController.doPrivileged(Native Method)
	at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1408)
	at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
	at sun.rmi.transport.Transport$1.run(Transport.java:200)
	at sun.rmi.transport.Transport$1.run(Transport.java:197)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
	at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property ' username' of bean class [org.apache.commons.dbcp2.BasicDataSource]: Bean property ' username' is not writable or has an invalid setter method. Did you mean 'username'?
	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1064)
	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:922)
	at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:82)
	at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:62)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1489)
	... 60 more

错误代码

这是在SSM项目中的applicationContext.xml配置文件中配置数据库中的代码:

    <!--引入外部配置文件(properties等文件-->
    <context:property-placeholder location="classpath:db.properties"/>
    <!-- 配置数据源 -->
    <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
        <property name="driverClassName" value="${driverClassName}"/>
        <property name="url" value="${url}"/>
        <property name=" username" value="${username}"/>
        <property name="password" value="${password}"/>
        <!-- 最大连接数 -->
        <property name="maxTotal" value="${maxTotal}"/>
        <!-- 最大空闲连接数 -->
        <property name="maxIdle" value="${maxIdle}"/>
        <!-- 初始化连接数 -->
        <property name="initialSize" value="${initialSize}"/>
    </bean>

原因

property标签的name属性值中的"username"有个空格。

解决

去掉空格。

正确代码

    <!--引入外部配置文件(properties等文件-->
    <context:property-placeholder location="classpath:db.properties"/>
    <!-- 配置数据源 -->
    <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
        <property name="driverClassName" value="${driverClassName}"/>
        <property name="url" value="${url}"/>
        <property name="username" value="${username}"/>
        <property name="password" value="${password}"/>
        <!-- 最大连接数 -->
        <property name="maxTotal" value="${maxTotal}"/>
        <!-- 最大空闲连接数 -->
        <property name="maxIdle" value="${maxIdle}"/>
        <!-- 初始化连接数 -->
        <property name="initialSize" value="${initialSize}"/>
    </bean>

 

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/cnds123321/article/details/104084251

智能推荐

Web墨卡托坐标与WGS84坐标互转_dreamgis的博客-程序员宅基地

转自:http://www.cnblogs.com/liongis/archive/2012/06/13/2548061.htmlWeb墨卡托坐标与WGS84坐标互转原文地址:http://bbs.esrichina-bj.cn/ESRI/thread-78245-1-1.html在WebGIS的开发中经常用到的地图投影为Web墨卡托和WGS84,故歌地图,bingmaps

学习项目-搜索引擎_acwing_220v电动⑧的博客-程序员宅基地

编译环境deepin-vim,这是一个基于github,新浪微博和boost库的简单搜索引擎的后端实现,前端具体实现我在github上面看见有两个非常完备的搜索引擎项目:https://github.com/mamengchen/searchEngine是一个基于RSS文本内容检索的轻量级搜索引擎https://github.com/mamengchen/Search_Project是一个...

java运用itextpdf批量添加书签_怪我冷i的博客-程序员宅基地_itextpdf 书签

java运用itextpdf批量添加书签带太多书不方便,但是电子书又普遍没有目录,这里开发了一个小工具用于生成书签。这个过程参考了很多大神们的资料。这里运用的工具是itextpdf,这个项目可以在windos下使用,也可以在Linux下使用。目录文件目录 7第一章 概率论的基本概念 1随机试验 1样本空间、随机事件 2频率与概率 5等可能概型(古典概型) 9条件概率 14独...

icloud文档本地存储_如何在iCloud存储上省钱_culul01313的博客-程序员宅基地

icloud文档本地存储The situation with iCloud storage would be funny if it wasn’t so ridiculous, and we’ve already made our feelings clear on whether Apple should offer more storage for free. But if you reall...

Sqoop 1.4.6环境安装以及数据迁移hdfs、hive、hive分区、hbase、增量导入、创建sqoop job(定时执行脚本方法)_Bright Huang的博客-程序员宅基地_sqoop 1.4.6 hbase 2.2

一、 Sqoop 安装安装 Sqoop 的前提是已经具备 Java 和 Hadoop、 Hive、 ZooKeeper、 HBase 的环境1.1 下载并解压链接:https://pan.baidu.com/s/1-i56m_mmLdKE_NqYpCzRhA提取码:t2c31.上传安装包 sqoop-1.4.6-cdh5.14.2.tar.gz 到虚拟机中2.解压 sqoop 安装包到指定目录 改名sqoop 方便使用tar -zxvf sqoop-1.4.6-cdh5.14.2.tar.gz

随便推点

搞定 Dubbo 系列(三):负载均衡策略和源码解析_编程者说的博客-程序员宅基地

loadBalance是现在服务端框架的标配,dubbo作为在互联网端流行这么多年的rpc框架,自然也少不了。现在的服务端一般都是集群部署,dubbo 需要对服务消费者的调用请求进行分配,避免少数服务提供者负载过大。一、四种负载均衡策略dubbo 提供了四种负载均衡策略,分别是, Random LoadBalance 随机(默认负载均衡策略),可以完全随机,也可以按权重设置随机概率。...

Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin_panyox的博客-程序员宅基地

参考Definily it will work:这个回答,感谢这个哥们,解决了我的问题https://stackoverflow.com/questions/25044403/mvn-deploy-maven-gpg-plugin1-5sign-failing-has-worked-for-a-week-now-no主要是添加&lt;gpgArguments&gt; &lt;arg&gt;--pinentry-mode&lt;/arg&gt;

记一次学习DNS隧道跳过无线网登陆验证过程_sunmuggle的博客-程序员宅基地

记一次学习DNS隧道跳过无线网登陆验证过程硬性要求工具:vps:35.220.243.222,内部ip10.170.0.3域名:sunmuggle.ml所需软件xshellvps端:dns2tcpwindows端:dns2tcpc准备工作:绑定域名和vps开启vps 防火墙操作:xshell登陆vps代码:用winscp把dns2tcp服务器端文件上传到服务器tar zxf d...

Heyy.... I've got some games. Post the games name, and I'll post it 4 u[小糊涂的灵感]_aochuolan7238的博客-程序员宅基地

Heyy.... I've got some games. Post the games name, and I'll post it 4 u. MaybeI can get new games, if you ask.MY GAMES:2Fast 2Furious .zip3D Motoracer .zipLegend Of Ninja 2 .jar...

linux系统下安装ImageMagick及其php imagick扩展_Jokenzhang的博客-程序员宅基地

linux系统下安装ImageMagick及其php imagick扩展首先准备工作PHP版本7.1.3ImageMagick版本 ImageMagick-7.0.8-3PHP扩展imagick版本 imagick-3.4.3RC3第一步-ImageMagick 安装ImageMagick网址http://www.imagemagick.org/script/install-source.php首先下载ImageMagick,新版本ImageMagick-7.0.8-31.下载Ima

如何用java给PDF添加一个图片水印?_慕枫520的博客-程序员宅基地

以下代码需要添加jar包: itextpdf-5.3.2.jarimport java.io.File;import java.io.FileOutputStream;import com.itextpdf.text.Image;import com.itextpdf.text.pdf.PdfContentByte;import com.itextpdf.text.pdf.PdfReader;im...

推荐文章

热门文章

相关标签