我有一个基于 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/