spring - Environment variables are not getting expanded in servlet.xml under JBoss -
problem: when embed environment variables in context xml, expanded when run locally. when deploy on openshift not. resolve null.
configuration: web.xml:
<context-param> <param-name>contextconfiglocation</param-name> <param-value>/web-inf/springapp.xml</param-value> </context-param>
springapp.xml:
<bean id="datasource" class="org.apache.commons.dbcp.basicdatasource" destroy-method="close"> <property name="driverclassname" value="com.mysql.jdbc.driver"/> <property name="url" value="jdbc:mysql://#{systemproperties['openshift_mysql_db_host']}:#{systemproperties['openshift_mysql_db_port']}/prepare?characterencoding=utf-8"/> <property name="username" value="aaa"/> <property name="password" value="bbb"/> </bean>
pom.xml:
- spring version 3.2.0.release
local development environment:
- intellij (environment variables set in config)
- tomcat7
openshift environment:
- tomcat 7 (jboss ews 2.0)
- environment variables set openshift. confirmed values 'env' command.
openshift_mysql_db_port=3306
openshift_mysql_db_host=127.3.xxx.yyy
the message on openshift (note server , port null):
org.apache.commons.dbcp.sqlnestedexception: cannot create jdbc driver of class 'com.mysql.jdbc.driver' connect url 'jdbc:mysql://:/prepare?characterencoding=utf-8'
my solution configuring local development , openshift jboss.
i gave trying expand env variables. worked fine straight tomcat, total no go jboss. switched nam's method.
openshift created correct jdbc connection in context.xml, nam said. needed same on local machine. duplicated placing in /usr/local/cellar/tomcat/7.0.39/libexec/conf/context.xml:
<resource name="jdbc/mysqlds" url="jdbc:mysql://localhost:3306/prepare?characterencoding=utf-8" driverclassname="com.mysql.jdbc.driver" username="aaa" password="bbb" auth="container" type="javax.sql.datasource" maxactive="20" maxidle="5" maxwait="10000" />
then removed <bean id=datasource...
springapp.xml.
finally changed datasource property sessionfactory to:
<bean id="sessionfactory" class="org.springframework.orm.hibernate4.localsessionfactorybean"> <property name="datasource"> <bean class="org.springframework.jndi.jndiobjectfactorybean"> <property name="jndiname" value="jdbc/mysqlds"/> <property name="resourceref" value="true"/> </bean> </property> <property name="packagestoscan" value="com.xxx.yyy.zzz"/> <property name="hibernateproperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.mysqlmyisamdialect</prop> <prop key="hibernate.show_sql">false</prop> </props> </property> </bean>
now context.xml tomcat takes care of local configuration. spring bean definitions have appropriate info.
Comments
Post a Comment