Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I access properties in a JAR file?
    primarykey
    data
    text
    <p>I'm using Spring 3.1.1.RELEASE. I'm having trouble accessing a properties file included in a JAR file. I have a JAR with this structure …</p> <pre><code>/encryption.properties /META-INF/spring/applicationContext-user.xml </code></pre> <p>In the "applicationContext-user.xml" file I have</p> <pre><code>&lt;!-- Define hashing properties --&gt; &lt;bean id="localPropertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; &lt;property name="location"&gt; &lt;value&gt;classpath:encryption.properties&lt;/value&gt; &lt;/property&gt; &lt;/bean&gt; ... &lt;beans:bean id="jasyptStringDigester" class="org.jasypt.digest.StandardStringDigester"&gt; &lt;beans:property name="algorithm"&gt; &lt;beans:value&gt;${digest.algorithm}&lt;/beans:value&gt; &lt;/beans:property&gt; &lt;beans:property name="provider"&gt; &lt;beans:ref bean="bcProvider" /&gt; &lt;/beans:property&gt; &lt;beans:property name="saltGenerator"&gt; &lt;beans:ref bean="saltGenerator" /&gt; &lt;/beans:property&gt; &lt;beans:property name="saltSizeBytes" value="${salt.bytes.length}" /&gt; &lt;/beans:bean&gt; </code></pre> <p>I include the above JAR in my WAR file (in its WEB-INF/lib directory) and when I deploy my WAR, I get the error</p> <pre><code>08:39:41,796 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-4) Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@129a92f: defining beans [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,accountDao,accessCodeDaoImpl,SBTrainerDaoImpl,trainingLinkDAOImpl,trainingSessionDAOImpl,opportunityDao,orderDao,orderLineItemDAO,myclientOrganizationDaoImpl,POForOpportunityDAO,quoteLineItemDaoImpl,SBPersonDaoImpl,trainingAssignmentDao,trainingLocationDaoImpl,accessCodeServiceImpl,opportunitiesService,orderService,trainingSessionService,standardsDaoImpl,standardsServiceImpl,stateDaoImpl,organizationTypeDaoImpl,countryDaoImpl,addressDaoImpl,organizationDao,addressServiceImpl,organizationTypeServiceImpl,organizationService,stateServiceImpl,countryServiceImpl,contractDaoImpl,productDaoImpl,contractServiceImpl,productServiceImpl,coreDaoImpl,roleDaoImpl,userDaoImpl,userServiceImpl,roleServiceImpl,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,localPropertyConfigurer,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,bcProvider,jasyptStringDigester,saltGenerator,passwordEncoder,applicationProperties,dataSource,entityManagerFactory,sharedEntityManager,transactionManager,myclientClient,updateOrdersJob,updateOrdersCronTrigger,updatePDJob,updatePDCronTrigger,org.springframework.scheduling.quartz.SchedulerFactoryBean#0,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy 08:39:41,802 ERROR [org.springframework.web.context.ContextLoader] (MSC service thread 1-4) Context initialization failed: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'jasyptStringDigester' defined in class path resource [META-INF/spring/applicationContext-user.xml]: Could not resolve placeholder 'digest.algorithm' at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:209) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE] at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:220) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE] at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:84) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE] at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:681) [spring-context-3.1.1.RELEASE.jar:3.1.1.RELEASE] at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:656) [spring-context-3.1.1.RELEASE.jar:3.1.1.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:446) [spring-context-3.1.1.RELEASE.jar:3.1.1.RELEASE] at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385) [spring-web-3.1.1.RELEASE.jar:3.1.1.RELEASE] at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284) [spring-web-3.1.1.RELEASE.jar:3.1.1.RELEASE] at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) [spring-web-3.1.1.RELEASE.jar:3.1.1.RELEASE] at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.10.Final.jar:] at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.10.Final.jar:] at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.0.Final.jar:7.1.0.Final] at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [classes.jar:1.6.0_37] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [classes.jar:1.6.0_37] at java.lang.Thread.run(Thread.java:680) [classes.jar:1.6.0_37] </code></pre> <p>So my question is, how am I supposed to properly reference my properties file in the JAR's application context file?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload