java.security.AccessControlException in Spring Application



我有一个在src/resources/database-context中描述的文件.xml

<context:property-placeholder 
location="file:#{systemProperties['CONF_DIR']}/environment.properties"
ignore-unresolvable="true"/>

由于某种原因,它没有被读取,我收到以下错误...

14:15:32.454 [main] WARN org.springframework.context.support.ClassPathXmlApplicationContext - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: environment.properties (The system cannot find the file specified)
    at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:89)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:265)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:162)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at com.mizuho.ats.main.LoanAdjust.main(LoanAdjust.java:80)
Caused by: java.io.FileNotFoundException: environment.properties (The system cannot find the file specified)

但真正的原因可能是访问控制问题...

14:15:32.282 [main] DEBUG org.springframework.core.SpringProperties - Could not retrieve system property 'spring.beaninfo.ignore': java.security.AccessControlException: access denied ("java.util.PropertyPermission" "spring.beaninfo.ignore" "read")
14:15:32.298 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Invoking afterPropertiesSet() on bean with name 'org.mybatis.spring.mapper.MapperScannerConfigurer#0'
14:15:32.298 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Finished creating instance of bean 'org.mybatis.spring.mapper.MapperScannerConfigurer#0'
14:15:32.298 [main] DEBUG org.springframework.core.env.StandardEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
14:15:32.298 [main] DEBUG org.springframework.core.SpringProperties - Could not retrieve system property 'spring.getenv.ignore': java.security.AccessControlException: access denied ("java.util.PropertyPermission" "spring.getenv.ignore" "read")

它无法读取条目...

14:43:45.274 [main] INFO org.springframework.core.env.StandardEnvironment - Caught AccessControlException when accessing system property [CONF_DIR];
    its value will be returned [null]. Reason: access denied ("java.util.PropertyPermission" "CONF_DIR" "read")

当然,该文件存在于路径中。并且有一个具有以下规范的安全策略文件...(可能它甚至没有加载。

grant {
    // Allow everything
    permission java.security.AllPermission;
};

原始应用程序是在只有 JDK 1.7 的环境中开发的,我正在开发 JDK 1.8 环境,尽管我在编译设置中明确指定了 1.7 JDK,在运行配置 JRE 设置中明确指定了 1.7 JRE。

可能是什么原因造成的?有什么解决方案吗?

答案是在 JRE 的 lib/安全策略文件中创建一个条目。

通常对于 Spring 应用程序,src/resources 策略文件就足够了,但由于某种原因它不是,特别是当日志/其他文件要从项目文件夹之外的位置读取时。这是一个运行时异常。

相关内容

  • 没有找到相关文章

最新更新