当前位置: 首页 > 知识库问答 >
问题:

带Spring靴的jasypt

史朗
2023-03-14

我正在使用jasypt spring boot starter:1.14和spring-boot-2.0.0。M2

如果application.properties在类路径(src/main/资源)中可用,它工作得非常好

即使应用程序运行正常,Spring boot也能正常工作。属性放在运行spring boot jar的文件夹中(默认情况下,它在当前文件夹中查找application.properties)

如果我将application.properties移出src/main/资源并将其放在根文件夹中,应用程序无法启动,并出现以下错误

nested exception is java.io.FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist
        at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:179) ~[spring-context-5.0.0.RC2.jar!/:5.0.0.RC2]
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:308) ~[spring-context-5.0.0.RC2.jar!/:5.0.0.RC2]
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:229) ~[spring-context-5.0.0.RC2.jar!/:5.0.0.RC2]
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:271) ~[spring-context-5.0.0.RC2.jar!/:5.0.0.RC2]
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94) ~[spring-context-5.0.0.RC2.jar!/:5.0.0.RC2]
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:686) ~[spring-context-5.0.0.RC2.jar!/:5.0.0.RC2]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:524) ~[spring-context-5.0.0.RC2.jar!/:5.0.0.RC2]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:122) ~[spring-boot-2.0.0.M2.jar!/:2.0.0.M2]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.0.0.M2.jar!/:2.0.0.M2]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) [spring-boot-2.0.0.M2.jar!/:2.0.0.M2]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.0.M2.jar!/:2.0.0.M2]

通过放置应用程序,我可以运行其他spring boot jar。运行spring boot的文件夹中的属性。但在与jasypt集成后,它就不起作用了

如果有任何机构面临此类问题,请回复

共有1个答案

申思远
2023-03-14

您必须手动解析配置路径。下面的示例实现,其中myapp.home是应用程序参数(或VM选项-

@Configuration
public class Config {
    ...

    @Bean
    private static PropertyPlaceholderConfigurer getCustomPropertyPlaceholderConfigurer() {
        String appPropertyFile = "application.properties";
        String myAppHome = System.getProperty("myapp.home") + + File.separatorChar + "conf";;
        PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
        final Resource extResource = new FileSystemResource( new File( myAppHome, appPropertyFile) );
        ppc.setLocations( new Resource[] { extResource } );
        ppc.setIgnoreUnresolvablePlaceholders( true );
        return ppc;
    }

    ...
}
 类似资料:
  • 我有两个项目。我用Angular2 cli构建的Angular2应用程序和只为Angular2应用程序服务的Spring Boot应用程序。我用构建Angular2应用程序,它会生成一个文件夹。然后,我将文件夹的内容放在Spring Boot应用程序的中。 我的Spring启动应用程序有两个文件。 Spring Boot应用程序类: 及其应用。属性文件: 它工作得很好,但是如果我转到一个url并点

  • 我是Spring Boot和MongoDb的新手。尝试使用Mongo存储库和Spring Boot的一些示例。但在浏览了一些文档后发现,Mongo模板是一个更好的选择。无法使用Mongo模板示例获得正确的Spring Boot。 > 有人能帮我举个同样的例子吗? 在尝试Mongo模板时,我们是否需要创建用户定义的存储库界面并扩展存储库或CRUD存储库?

  • 我有一个Spring Boot项目,使用Jersey作为我的REST服务,并使用AngularJS进行我的前端开发。当我在不使用任何控制器的情况下运行它并转到index.html(位于resource/statig/index.html中)时,它运行得很好。当我添加一个控制器时,它呈现给出字符串“index.html”作为输出。Spring Boot配置: 球衣配置: 控制器类:

  • 3)引用了mongeez.location={myDir}/db中的位置 我在启动应用程序时处于异常之下 由:com.mongodb.mongoCommandException引起:命令失败,错误为59(CommandNotFound):“在服务器本地主机:27017上没有这样的命令:'$eval'.完整的响应是{“ok”:0.0,“errmsg”:“no suck command:'$eval'

  • 我是一名实习生,我正在尝试学习Liquibase,看看我们是否可以将其用于我们的应用程序。我使用了Git Bash中的Liquibase,没有任何问题(在更新和回滚方面都很好),然后我尝试将Liquibase与Spring Boot项目一起使用,看看是否能够更新数据库。我做到了,我通过Spring Boot创建并更新了db。但接下来我想做一些回滚,但我不能,我不知道该做什么。我试着在Git Bas