我有一个基于 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")
同样的结果
我还尝试将其放入我的 1 个配置类中:
@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;
}
}