<import resource="classes/test/test.xml" />或者
<import resource="classpath:test/test.xml" />

解决方案 »

  1.   

    好多方法啊,关键在于你已经对路径问题非常清晰了,
    我一般写自己的类继承spring资源加载类,按我的意思加载。
    http://blog.csdn.net/sunyujia/archive/2008/09/21/2957481.aspx
    http://blog.csdn.net/sunyujia/archive/2008/01/05/2027087.aspx
    http://blog.csdn.net/sunyujia/archive/2008/06/01/2501720.aspx
      

  2.   

    一楼的同学请仔细审题test.xml里面怎么写不是怎么import给别人
      

  3.   

    无语中,需要点学习能力的,没听说过csdn都是保姆吗???
    想不被javaeye鄙视吗,就要点学习能力,非得给代码才行啊。一个字母都不差就是针对性。
    重复回答太多遍的问题,做做广告行不行。
      

  4.   

    package com;import org.springframework.context.support.FileSystemXmlApplicationContext;public class Test {
    private String name; public static void main(String[] args) throws Exception {
    java.net.URL url = com.Test.class.getResource("test.xml");
    FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(
    url.getFile());
    System.out.println(((Test)context.getBean("testBean")).getName());
    } public String getName() {
    return name;
    } public void setName(String name) {
    this.name = name;
    }
    }
    package com;import java.io.File;
    import java.io.UnsupportedEncodingException;
    import java.net.MalformedURLException;
    import java.net.URL;import org.springframework.core.io.Resource;
    import org.springframework.core.io.UrlResource;public class Loader extends
    org.springframework.beans.factory.config.PropertyPlaceholderConfigurer {
    /*
     * Description:取得当前类所在的文件
     *
     * @param clazz @return @mail [email protected] @since:Sep 21, 2008 12:32:10
     * PM
     */
    public static File getClassFile(Class clazz) {
    URL path = clazz.getResource(clazz.getName().substring(
    clazz.getName().lastIndexOf(".") + 1)
    + ".class");
    if (path == null) {
    String name = clazz.getName().replaceAll("[.]", "/");
    path = clazz.getResource("/" + name + ".class");
    }
    return new File(path.getFile());
    } /**
     *
     * Description:取得当前类所在的ClassPath目录
     *
     * @param clazz
     * @return
     * @mail [email protected]
     * @since:Sep 21, 2008 12:32:27 PM
     */
    public static File getClassPathFile(Class clazz) {
    File file = getClassFile(clazz);
    for (int i = 0, count = clazz.getName().split("[.]").length; i < count; i++)
    file = file.getParentFile();
    if (file.getName().toUpperCase().endsWith(".JAR!")) {
    file = file.getParentFile();
    }
    return file;
    } /**
     *
     * Description: 同getClassPathFile 解决中文编码问题
     *
     * @param clazz
     * @return
     * @mail [email protected]
     * @since:Sep 21, 2008 1:10:37 PM
     */
    public static String getClassPath(Class clazz) {
    try {
    return java.net.URLDecoder.decode(getClassPathFile(clazz)
    .getAbsolutePath(), "UTF-8");
    } catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    return "";
    }
    } public void setLocation(Resource location) {
    File file=Loader.getClassPathFile(Loader.class).getParentFile().getParentFile();
    System.out.println(file+location.getFilename());
    File f=new File(file.getAbsolutePath()+"\\"+location.getFilename());
    try {
    super.setLocation(new UrlResource(f.toURL()));
    } catch (MalformedURLException e) {
    e.printStackTrace();
    }
    }
    }
      

  5.   

    applicationContext.xml<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    <bean id="testBean" class="com.Test">
    <property name="name" ><value>${name}</value></property>
    </bean>
    </beans>
    test.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    <import resource="./../applicationContext.xml" />
    <bean id="propertyConfigurer"
    class="com.Loader">
    <property name="location">
    <value>config.properties</value>
    </property>
    </bean>
    </beans>
      

  6.   

    config.properties内容
    name=csdn
    程序输出
    csdn问答此问题的全部知识点,来自我的3篇博客。楼上还想说什么。