java - value from properties file is returning null -



java - value from properties file is returning null -

i have variable beingness set in external .properties file, when seek phone call value, keeps returning null. have project importing external .properties file works fine, using model can't figure out why 1 isn't working. relevent files below.

specifically returning null propertiesutil.getproperty("property.file.variable");

web.xml

<?xml version="1.0" encoding="utf-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="webapp_id" version="2.5"> <display-name>project</display-name> <servlet> <servlet-name>jersey rest service</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.servletcontainer</servlet-class> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>com.bar.foo.rest</param-value> </init-param> <init-param> <param-name>contextconfiglocation</param-name> <param-value>classpath:applicationcontext.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>jersey rest service</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> <listener> <listener-class>com.bar.foo.rest.listenerclass</listener-class> </listener> </web-app>

applicationcontext.xml

<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <tx:annotation-driven /> <context:annotation-config /> <mvc:annotation-driven /> <context:component-scan base-package="com.bar.foo;" /> <context:property-placeholder location="file:${externalconfiguration}" /> <bean id="propertyconfigurer" class="com.bar.foo.utils.propertiesutil"> <property name="ignoreresourcenotfound" value="true" /> <property name="ignoreunresolvableplaceholders" value="true" /> <property name="locations"> <list> <value>classpath:project.properties</value> <value>file:${externalconfiguration}</value> </list> </property> </bean> <bean id="configproperties" class="org.springframework.beans.factory.config.propertiesfactorybean"> <property name="ignoreresourcenotfound" value="true" /> <property name="locations"> <list> <value>classpath:project.properties</value> <value>file:${externalconfiguration}</value> </list> </property> </bean> </beans>

pom.xml

<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <parent> <groupid>com.bar</groupid> <artifactid>project</artifactid> <version>1.30.1-snapshot</version> </parent> <artifactid>project</artifactid> <packaging>war</packaging> <properties> <org.springframework-version>3.1.0.release</org.springframework-version> <spring.batch.version>3.0.0.release</spring.batch.version> </properties> <build> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifactid> <!-- <version>2.3.2</version> --> <configuration> <source>1.6</source> <target>1.6</target> <compilerargument>-xlint:all</compilerargument> <showwarnings>true</showwarnings> <showdeprecation>true</showdeprecation> </configuration> </plugin> <plugin> <groupid>org.codehaus.mojo</groupid> <artifactid>exec-maven-plugin</artifactid> <version>1.2.1</version> <configuration> <mainclass>org.test.int1.main</mainclass> </configuration> </plugin> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-surefire-plugin</artifactid> <version>2.16</version> <configuration> <argline>-xx:-usesplitverifier</argline> </configuration> </plugin> </plugins> </build> <dependencies> <!-- dependency (version unspecified) needed @ runtime tomcat. don't know why had add together manually. --> <dependency> <groupid>asm</groupid> <artifactid>asm</artifactid> <version>3.3.1</version> <scope>runtime</scope> </dependency> <dependency> <groupid>com.sun.jersey</groupid> <artifactid>jersey-bundle</artifactid> <version>1.10</version> </dependency> <dependency> <groupid>javax.jdo</groupid> <artifactid>jdo2-api</artifactid> <version>2.3-eb</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-jdbc</artifactid> <version>${org.springframework-version}</version> <exclusions> <!-- exclude commons logging in favor of slf4j --> <exclusion> <groupid>commons-logging</groupid> <artifactid>commons-logging</artifactid> </exclusion> </exclusions> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-context-support</artifactid> <version>${org.springframework-version}</version> <exclusions> <!-- exclude commons logging in favor of slf4j --> <exclusion> <groupid>commons-logging</groupid> <artifactid>commons-logging</artifactid> </exclusion> </exclusions> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-context-support</artifactid> <version>${org.springframework-version}</version> <exclusions> <!-- exclude commons logging in favor of slf4j --> <exclusion> <groupid>commons-logging</groupid> <artifactid>commons-logging</artifactid> </exclusion> </exclusions> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-web</artifactid> <version>${org.springframework-version}</version> <exclusions> <!-- exclude commons logging in favor of slf4j --> <exclusion> <groupid>commons-logging</groupid> <artifactid>commons-logging</artifactid> </exclusion> </exclusions> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-webmvc</artifactid> <version>${org.springframework-version}</version> </dependency> </dependencies> </project>

propertiesutil.java

package com.bar.foo.utils; import java.util.hashmap; import java.util.map; import java.util.properties; import org.springframework.beans.factory.config.configurablelistablebeanfactory; import org.springframework.beans.factory.config.propertyplaceholderconfigurer; public class propertiesutil extends propertyplaceholderconfigurer { private static map<string, string> propertiesmap = new hashmap<string, string>(); // default in propertyplaceholderconfigurer private int springsystempropertiesmode = system_properties_mode_fallback; /** * workaround: propertyplaceholderconfigurer.systempropertiesmode not * straight accessible */ @override public void setsystempropertiesmode(int systempropertiesmode) { super.setsystempropertiesmode(systempropertiesmode); springsystempropertiesmode = systempropertiesmode; } @override protected void processproperties(configurablelistablebeanfactory beanfactory, properties props) { super.processproperties(beanfactory, props); (object key : props.keyset()) { string keystr = key.tostring(); string valuestr = resolveplaceholder(keystr, props, springsystempropertiesmode); propertiesmap.put(keystr, valuestr); } } public static string getproperty(string name) { homecoming propertiesmap.get(name); } }

found solution. turns out web.xml setup wrong. had tried right syntax, bad configuration of tomcat server caused error (noclassdeffounderror: javax.servlet.servletexception) deploying project on different server instance seemed fix. right configuration below:

add web.xml:

<servlet> <servlet-name>appservlet</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name>contextconfiglocation</param-name> <param-value>classpath:applicationcontext.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet>

java spring maven properties

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -