此篇博客缘起:部署java web系统到阿里云服务器(ubuntu14.04)的时候,有以下两个问题 找不到自定义的property配置文件 上传图片的时候找不到路径 开发的时候是在windows上的,运行正常,部署的时候就出问题了,肯定是windows和linux路径区别导致的(一个小问题来回鼓捣了几个小时,因为有自己对windows下和linux下的区别还不是特别了解,还有就是每次在windows下修改完成以后都要重新上传到阿里云,项目较大来回也需要较多时间...),遂决定好好看看java…
分类: [java]2013-12-09 16:29 1020人阅读 评论(0) 收藏 举报 1.简介 在SSH框架下,假设我们将配置文件放在项目的src/datasource.properties路径下,Spring的配置文件也是src/applicationContext.xml路径下,那么我们可以借助Spring的property-placeholder读取配置文件,然后注入Bean中.我们在程序中,可以根据Bean的Id,获取注入的值.这样我们就可以借助Spring来读取配置文件. 2.…
Spring 读取配置文件并调用 bean package cn.com.test.receive; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class…
注册 @Configuration 标识的类,spring 读取配置文件的时候该类会被自动装载 package cn.com.receive;import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Config…
Spring在读取配置文件时,是相对于bin,或者WEB-INF的: “applicationContext.xml”就是找bin或WEB-INF及子文件夹下的文件: “/res/applicationContext.xml”就是必须bin或WEB-INF文件夹下的res文件夹的文件://res可以换掉: 下面是找的一些关于相对路径和绝对路径的资料: 转自:http://www.cnblogs.com/mabaishui/archive/2011/03/17/1987226.html 1.基本概…
Spring读取配置XML文件分三步: 一.新建一个Java Bean: package springdemo; public class HelloBean { private String helloWorld; public String getHelloWorld() { return helloWorld; } public void setHelloWorld(String helloWorld) { this.helloWorld = helloWorld; } } 二.构建一个配…
BeanFactory有很多实现类,通常使用 org.springframework.beans.factory.xml.XmlBeanFactory类.但对于大部分J2EE应用而言,推荐使 用ApplicationContext. ApplicationContext是 BeanFactory的子接口,其常用实现类是 org.springframework.context.support.FileSystemXmlApplicationContext和 org.springframework.…
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.Reader; import java.util.Properties; import org.junit.Test; import org.springframework.core.io.ClassPathResour…
最近在学习Spring如何读取配置文件,记录下方便自己也方便别人: 大致分为两类吧,一种的思路是利用Spring的beanFactoryPostProcessor读取配置文件内容到内存中,也就是应用程序的某个对象的属性中,然后设置上去: 另外一种思路就是SPEL表达式,这是Spring3.x的特性,依赖于Spring expression: 简单介绍下 #{}和  ${}用法上一个小的区别: ${}如果需要写默认值的话  ${keyname  :  defaultValue } #{}如果需要写…
spring读取dubbo xml文件,在本项目内可以调用正常,一旦把改项目打成jar包,供其他项目调用,就会提示找不到配置文件 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:app-dubbo-client-context.xml");  有找到 app-dubbo-client-context.xml , cannot be opened because …