<?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" xmlns:util="http://www.springframework.org/schema/util" 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 http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"> <context:annotation-config/> <!-- picks up and registers AppConfig as a bean definition --> <context:component-scan base-package="com.web.spring.other" /> <bean class="com.web.spring.other.AppConfig"/> 方法一 <context:property-placeholder location="classpath:jdbc.properties" /> 方法二 <util:properties id="jdbcProperties" location="classpath:jdbc.properties"/> </beans>实现一
package com.web.spring.other; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportResource; @Configuration @ImportResource("classpath*:spring/spring-properties.xml") public class AppConfig { private @Value("${jdbc.driverClassName}") String driverClassName; @Bean(initMethod = "init") public JDBCBean jdbc(){ JDBCBean jdbc=new JDBCBean(); jdbc.setDriverClassName(driverClassName); return jdbc; } } jdbc.driverClassName=org.hsqldb.jdbcDriver实现二
package com.web.spring.other; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class AppConfig { private @Value("#{jdbcProperties.driverClassName}") String driverClassName; //private @Value("#{jdbcProperties['jdbc.driverClassName']}") String driverClassName; @Bean(initMethod = "init") public JDBCBean jdbc(){ JDBCBean jdbc=new JDBCBean(); jdbc.setDriverClassName(driverClassName); return jdbc; } } driverClassName=org.hsqldb.jdbcDriver
--------------------------------------------------------------------------------------------------- 一、只读取单个 properties 文件
1、在 spring 的配置文件中,加入
引入命名空间:
xmlns:util=”http://www.springframework.org/schema/util” xsi:schemaLocation=”http://www.springframework.org/schema/utilhttp://www.springframework.org/schema/util/spring-util-3.0.xsd”
内容中写入<util:properties id=”propertiesReader” location=”classpath:test.properties” />
2、在类中需要注入的属性实现 setter 和 getter 方法。
3、在 setter 方法前,添加 @Value 注解
@Value(“#{propertiesReader[propertiesName]}”)
propertiesName 为 properties 文件中的键。这样,在容器启动过程中, Spring 将自动注入值。
二、读取多个 properties 文件与上类似,只是在配置文件写入的内容不同。
<bean id=”propertiesReader” class=”org.springframework.beans.factory.config.PropertiesFactoryBean”> <property name=”locations”> <list> <value>classpath:param.properties</value> <value>classpath:base.properties</value> </list> </property> </bean>
相关推荐
activiti和springboot整合只使用application.properties配置文件,解决了jdbc长时间待机连接被收回报错。使用springProcessEngineConfiguration对activiti管理
spring-mvc.xml spring-mybatis.xml web.xml log4j.properties,项目中需要用到的配置文件。直接可用。
config.properties:数据库配置文件 log4j.properties:mybatis日志文件 spring-mvc.xml:spring-MVC配置文件 spring-mybatis.xml:mybatis的配置文件 spring.xml
主要介绍了Spring Boot中配置文件application.properties使用及spring boot读取application.properties文件的方式,需要的朋友参考下吧
这是一个简单的案例用来实现Spring中jdbc.properties属性文件进行密文处理,代码中的学生实体自己根据需要在数据库中进行创建
主要介绍了详解spring boot 使用application.properties 进行外部配置,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
redis-context.xml redis和spring配置,需要引用到自己项目的spring配置文件里面 redis.properties redis的配置项,ip一级连接池参数,注意:redis默认没有密码,所以我的spring配置文件把密码注释掉了,如果有密码...
Spring Boot 是一款基于 Spring 框架的快速开发框架,它通过自动配置和约定大于...该配置文件将深入介绍 Spring Boot 项目中 application.properties 的超配置功能,帮助开发者更好地理解和利用这一强大的配置机制。
Spring-Boot-application.properties 描述,中文解释springboot 的application.properties 中每个配置是什么意思。
在本文中我们给大家整理了关于Spring Boot 的配置文件 application.properties的相关知识点内容,需要的朋友们参考学习下。
spring boot 配置文件
在Spring Boot中,可以使用配置文件来管理应用程序的配置。这些配置文件可以根据不同的环境进行分离和管理,Spring Boot提供了多种灵活的方式来实现多环境配置。 1. 配置文件的命名 默认配置文件:application....
log4j.properties 日志文件 *.properties配置文件 Struts.xml 配置action WebRoot根目录 fckeditor在线编辑器, images img 图片 upload,updown 上传下载, admin common 前台JSP页面 WEB-INF (lib+jsp+*.xml) ...
log4j.properties 日志文件 *.properties配置文件 Struts.xml 配置action WebRoot根目录 fckeditor在线编辑器, images img 图片 upload,updown 上传下载, admin common 前台JSP页面 WEB-INF (lib+jsp+*.xml) ...
可以从Jar外部加载JDBC.properties的Spring-mybatis配置文件,直接可以用,适合部署可执行jar时,从外部配置数据库
是否struts过滤器中提供的静态内容应该被浏览器缓存在头部属性中 struts.serve.static Whether the Struts filter should serve static content or not 是否struts过滤器应该提供静态内容 struts.tag....
Spring配置文件 <bean class="com.tinet.ccic.config.RedisPropertySourcesPlaceholderConfigurer"> <value>classpath*:app.properties 设置环境变量或JVM启动参数 环境变量方式 export config.server=...
在xml配置文件中,这样加载properties文件 <bean id="propertyConfigurer" class="com.better517na.propertiesComponent.business.ExtendedPropertyPlaceholderConfigurer"> <value>classpath:...
Spring3.0 配置文件中加载Properties文件的小例子
只要有了这个配置,然后配置JSP渲染器为JSTL支持的,那么在你的JSP文件中使用fmt标记就可以实现客户浏览器语言国际化了。 如:<fmt:message key="info.login.title" /> 其中的info.login.title和你的资源文件对应