Spring配置和简单属性
来源:互联网 发布:c语言游戏源代码网站 编辑:程序博客网 时间:2024/04/28 03:34
在Spring文档中:
Annotation-based container configuration
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:annotation-config/></beans>
3.4.2.1 Straight values (primitives, Strings
, and so on)
The value
attribute of the <property/>
element specifies a property or constructor argument as a human-readable string representation. As mentioned previously, JavaBeans PropertyEditors
are used to convert these string values from a String
to the actual type of the property or argument.
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"><!-- results in a setDriverClassName(String) call --><property name="driverClassName" value="com.mysql.jdbc.Driver"/><property name="url" value="jdbc:mysql://localhost:3306/mydb"/><property name="username" value="root"/><property name="password" value="masterkaoli"/></bean>
The following example uses the p-namespace for even more succinct XML configuration.
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"><bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" p:driverClassName="com.mysql.jdbc.Driver" p:url="jdbc:mysql://localhost:3306/mydb" p:username="root" p:password="masterkaoli"/></beans>
The preceding XML is more succinct; however, typos are discovered at runtime rather than design time, unless you use an IDE such as IntelliJ IDEA or the SpringSource Tool Suite (STS) that support automatic property completion when you create bean definitions. Such IDE assistance is highly recommended.
You can also configure a java.util.Properties
instance as:
<bean id="mappings" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <!-- typed as a java.util.Properties --> <property name="properties"> <value> jdbc.driver.className=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/mydb </value> </property></bean>
- Spring配置和简单属性
- [Spring]简单Junit和Spring整合配置
- Spring Boot 属性配置和使用
- Spring Boot 属性配置和使用
- Spring Boot 属性配置和使用
- Spring Boot 属性配置和使用
- Spring Boot 属性配置和使用
- Spring Boot 属性配置和使用
- Spring Boot 属性配置和使用
- Spring Boot 属性配置和使用
- Spring Boot 属性配置和使用
- Spring Boot 属性配置和使用
- Spring简单属性注入和集合属性注入
- Spring Boot学习笔记-项目属性的简单配置
- 【Spring Boot】Spring Boot 属性配置和使用
- Spring简单属性注入
- spring 简单属性注入
- JSF和Spring集成2--简单配置
- java远程调用rmi入门实例
- Tomcat提供的session持久化
- Julia语法手册
- Android中ListView分页加载数据
- 手把手教你把Vim改装成一个IDE编程环境(图文)
- Spring配置和简单属性
- SQL执行自动备份
- 网页图片自适应手机宽度
- Android 自带图标库 android.R.drawable
- Android requires compiler compliance level 5.0 or 6.0. Found '1.3' instead.
- VC++中改变CTreeCtrl子项Item的字体和颜色
- 使用hadoop实现关联商品统计
- Eclipse在调试程中出现java.lang.NoClassDefFoundError的解决方案
- web栏目置顶