在上下文问题中添加系统参数和应用程序

时间:2011-12-08 22:19:46

标签: java java-ee tomcat tomcat6 jasypt

第一部分:我被要求在我的启动命令中添加-DAPP_ENCRYPTION_PW = pw,因为属性文件存储加密的db密码而不是明文? :S所以我在JAVA_OPTS中添加了它。替代 - >在Catalina.sh中添加了参数。如果我错在这里请告诉我!还提供了答案,以及如何做的步骤!!!

第二部分:我在webapps(aapbase)文件夹中部署了一个war文件。试图通过TomcatManager启动它,但它给了我这个错误:application at context path could not be started ...

对于在这里做什么,有没有人有某种想法? 仅供参考:使用tomcat 6 ... 当我在Tomcat 6中运行它时,我收到此错误。

错误:

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.NullPointerException
    at org.jasypt.encryption.pbe.config.SimplePBEConfig.getPasswordCharArray(SimplePBEConfig.java:434)
    at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.resolveConfigurationPassword(StandardPBEByteEncryptor.java:740)
    at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.initialize(StandardPBEByteEncryptor.java:590)
    at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.initialize(StandardPBEStringEncryptor.java:570)
    at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.decrypt(StandardPBEStringEncryptor.java:697)
    at org.jasypt.properties.PropertyValueEncryptionUtils.decrypt(PropertyValueEncryptionUtils.java:72)
    at org.jasypt.spring.properties.EncryptablePropertyPlaceholderConfigurer.convertPropertyValue(EncryptablePropertyPlaceholderConfigurer.java:108)
    at org.springframework.beans.factory.config.PropertyResourceConfigurer.convertProperty(PropertyResourceConfigurer.java:121)
    at org.springframework.beans.factory.config.PropertyResourceConfigurer.convertProperties(PropertyResourceConfigurer.java:104)
    at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:81)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:668)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:643)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:437)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:294)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:215)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

2 个答案:

答案 0 :(得分:0)

如果您使用的是JVM系统属性(使用-D)中设置的密码,则应使用EnvironmentPBEConfig或EnvironmentStringPBEConfig配置对象,而不是您似乎正在使用的SimplePBEConfig对象。

该EnvironmentPBEConfig对象将允许您设置包含加密密码的JVM系统属性的名称(setPasswordSysPropertyName(“APP_ENCRYPTION_PW”)),从而使jasypt正确读取并使用此密码。

问候。

答案 1 :(得分:0)

虽然这个问题已经很老了,但我在为mule设置jasypt 1.9.2时遇到了同样的NPE。确保配置了'org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig'的'passwordSysPropertyName'属性。它应该可以解决这个问题。

<spring:bean id="environmentVariablesConfiguration"
    class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
    <spring:property name="algorithm" value="PBEWithMD5AndDES" />
    <spring:property name="passwordSysPropertyName" value="MULE_ENCRYPTION_PASSWORD" />
</spring:bean>