【问题标题】:Spring classpath variable not workingSpring类路径变量不起作用
【发布时间】:2015-05-03 00:01:29
【问题描述】:

我正在尝试使用classpath 变量,但我总是得到FileNotFoundException

<?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:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
       http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">


    <tx:annotation-driven />
    <context:component-scan base-package="ar.com.conexia.salud.*" />

    <bean id="pdfGenerator" class="ar.com.conexia.generator.PdfGenerator">
<!--        <constructor-arg
            value="#{systemProperties['catalina.home']}/webapps/COMEI_Beneficiario/WEB-INF/classes/reports/" /> -->
        <constructor-arg value="classpath:/reports/" />
        <constructor-arg value="C://reports//" />
    </bean>

</beans>

如您所见,我尝试使用 catalina.home 变量作为替代方法来检查我的文件没有任何其他问题,这很好。

谢谢。

编辑:我将这些基本路径与文件名连接起来以打开文件。

【问题讨论】:

    标签: java xml spring applicationcontext


    【解决方案1】:

    试试这个 在xml文件中放

    <context:component-scan base-package="com.your.package.name" />
    

    并创建类

    @Configuration
    public class Config {
        @Bean
        public PdfGenerator sessionFactoryBean(){
            PdfGenerator pdfGen=new PdfGenerator("classpath:/reports/","C://reports//");
            return pdfGen;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2014-01-20
      • 2016-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-12
      • 2015-03-15
      • 1970-01-01
      相关资源
      最近更新 更多