java - 解决 Spring MVC 3.2.8 中的占位符

标签 java spring spring-mvc property-placeholder

我有一个基于 Spring Web Model View Controller (Spring MVC 3.2.8 ) 的应用程序,我想解析占位符

我有文件application.properties文件夹内/src/main/resources/config/

这是我的课:

@Service("jobone")
@PropertySource("classpath:config/application.properties")
public class MyJobOne {

    private static final Logger LOGGER = Logger.getLogger   (MyJobOne.class);

    private File localDirectory = new File("tmpFtpFiles");

    private AbstractInboundFileSynchronizer<?> ftpInboundFileSynchronizer;

    @Autowired
    private SessionFactory myFtpSessionFactory;

    private boolean autoCreateLocalDirectory = true;

    private boolean deleteLocalFiles = true;

    private String fileNamePattern="*.*";


    @Value("${ftpRemoteDirectory}")
    private String remoteDirectory;

    ...
}

但是我运行应用程序时遇到此错误。

Caused By: java.lang.IllegalArgumentException: Could not resolve placeholder 'ftpRemoteDirectory' in string value "${ftpRemoteDirectory}"

我也尝试过@PropertySource("classpath:/config/application.properties")结果相同

我还尝试将其放入我的配置类之一:

@Configuration
@PropertySource("classpath:/config/application.properties")
public class FtpConfiguration {


    @Autowired
    private SessionFactory myFtpSessionFactory;

    @Bean
    @Scope(value="step")
    public FtpGetRemoteFilesTasklet myFtpGetRemoteFilesTasklet()
    {
        FtpGetRemoteFilesTasklet  ftpTasklet = new FtpGetRemoteFilesTasklet();
        ftpTasklet.setRetryIfNotFound(true);
        ftpTasklet.setDownloadFileAttempts(3);
        ftpTasklet.setRetryIntervalMilliseconds(10000);
        ftpTasklet.setFileNamePattern("README");
        //ftpTasklet.setFileNamePattern("TestFile");
        ftpTasklet.setRemoteDirectory("/");
        ftpTasklet.setLocalDirectory(new File(System.getProperty("java.io.tmpdir")));
        ftpTasklet.setSessionFactory(myFtpSessionFactory);

        return ftpTasklet;
    }

    @Bean   
    public SessionFactory myFtpSessionFactory()
    {
        DefaultFtpSessionFactory ftpSessionFactory = new DefaultFtpSessionFactory();
        ftpSessionFactory.setHost("la.mare.superiora");
        ftpSessionFactory.setClientMode(0);
        ftpSessionFactory.setFileType(0);
        ftpSessionFactory.setPort(1029);
        ftpSessionFactory.setUsername("carbonell");
        ftpSessionFactory.setPassword("nicinc");

        return ftpSessionFactory;
    }
}

最佳答案

试试这个。

@PropertySource("classpath:/config/application.properties") in your confiuration class.

关于java - 解决 Spring MVC 3.2.8 中的占位符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45030909/

相关文章:

java - 为什么我的形状不能在 JFrame 上绘制?

spring - JASIG CAS : single sign out not working

spring - LDAP认证

java - Websocket 与 Spring mvc、stomp、sockjs、Angular JS

java - java中输出时间戳的Util类

java - 从 Http 响应读取数据很少引发 BindException : Address already in use

java - apache shiro saltedauthentication.hashProvidedCredentials 遇到问题,未给出预期的哈希值

java - Spring RestTemplate 将响应流式传输到另一个请求中

asp.net-mvc - Java Spring MVC 中的 ASP.NET MVC 部分 View

java - 如何检查两条路径是否在同一个挂载点上?