bean.xml文件p标签使用报错
The prefix "p" for attribute "p:某属性" associated with an element type "bean" is not bound.
某元素属性未捆绑,直接点击添加p的命名空间,或者手动在<beans>里面添加一行约束
1
|
xmlns:p="http://www.springframework.org/schema/p" |
spring 的xml配置使用p标签简化
1、常见配置
比如配置数据源 读取properties
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
<!-- 配置阿里巴巴数据源 --> < bean id = "dataSource" class = "com.alibaba.druid.pool.DruidDataSource" init-method = "init" destroy-method = "close" > < property name = "url" value = "${jdbc.url}" /> < property name = "username" value = "${jdbc.username}" /> < property name = "password" value = "${jdbc.password}" /> < property name = "filters" value = "wall,stat,log4j" /> < property name = "maxActive" value = "300" /> < property name = "initialSize" value = "1" /> < property name = "maxWait" value = "60000" /> < property name = "minIdle" value = "1" /> < property name = "timeBetweenEvictionRunsMillis" value = "3000" /> < property name = "minEvictableIdleTimeMillis" value = "300000" /> < property name = "validationQuery" value = "SELECT 'x'" /> < property name = "testWhileIdle" value = "true" /> < property name = "testOnBorrow" value = "false" /> < property name = "testOnReturn" value = "false" /> < property name = "poolPreparedStatements" value = "true" /> < property name = "maxPoolPreparedStatementPerConnectionSize" value = "20" /> </ bean > |
可以配置如下
1
2
3
|
< bean id = "dataSource" class = "org.apache.commons.dbcp.BasicDataSource" destroy-method = "close" p:driverClassName = "org.gjt.mm.MySQL.Driver" p:url = "jdbc:mysql://127.0.0.1:3306/easyjf-bbs" p:username = "root" p:password = "mysql" /> < / beans > |
p表示对该bean里面的属性进行注入,格式为p:属性名=注入的对象
效果与在bean里面使用<property>标签一样
以上为个人经验,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/IRainReally/article/details/80507626