Knowledge Walls
J2EE Technologies Tutorial
Hyderabad, Andhra Pradesh, India
How to access system properties in spring configuration with example
5929 Views
Hints 
Below is an example of "How to access system properties in spring configuration with example"
Step.1 Start a Java Project with required jars 
  1. Open Eclipse
  2. Click on menu New -> Others
  3. In wizards type "Java Project" and Select "Java Project"
  4. Click Next
  5. Enter project name as "SystemPropertiesExample", then click Next
  6. Goto Libraries tab, then click on Add External JARs, then select Spring's 21 Framework Jars and commons-logging-1.1.jar.
  7. Click Finish.
Step.2 Project Explorer Preview 
PropertiesHolder.java
import java.util.Properties;


public class PropertiesHolder {
	private Properties sysProps;
	
	public Properties getSysProps() {
		return sysProps;
	}
	public void setSysProps(Properties sysProps) {
		this.sysProps = sysProps;
	}
}
bean-configuration.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:p="http://www.springframework.org/schema/p"
	xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">

	<bean id="pholder" class="PropertiesHolder">
		<property name="sysProps" value="#{systemProperties}" />
	</bean>
</beans>
SpringRunner.java
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


public class SpringRunner {
	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext("bean-configuration.xml");
		PropertiesHolder holder = (PropertiesHolder) context.getBean("pholder");
		
		System.out.println("
System Properties");
		for (Object key:holder.getSysProps().keySet()){
			System.out.println(key+"="+holder.getSysProps().get(key));
		}
	}
}
Output 
System Properties
java.runtime.name=Java(TM) SE Runtime Environment
sun.boot.library.path=D:\java\jre6\bin
java.vm.version=16.0-b13
java.vm.vendor=Sun Microsystems Inc.
java.vendor.url=http://java.sun.com/
path.separator=;
java.vm.name=Java HotSpot(TM) Client VM
file.encoding.pkg=sun.io
sun.java.launcher=SUN_STANDARD
user.country=US
sun.os.patch.level=
java.vm.specification.name=Java Virtual Machine Specification
user.dir=D:\Spring3.0Examples\SystemPropertiesExample
java.runtime.version=1.6.0_18-b07
java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs=D:\java\jre6\lib\endorsed
os.arch=x86
java.io.tmpdir=C:\Users\Beyond\AppData\Local\Temp\
line.separator=

java.vm.specification.vendor=Sun Microsystems Inc.
user.variant=
os.name=Windows 7
sun.jnu.encoding=Cp1252
java.library.path=D:\java\jre6\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files (x86)\PC Connectivity Solution\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\;C:\Program Files\Java\jre6\bin;C:\Program Files (x86)\Java\jre6\bin;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files (x86)\MySQL\MySQL Server 5.1\bin;C:\Program Files (x86)\BaseX\bin;C:\Users\Beyond\Downloads\jad;C:\Program Files (x86)\Java\jdk1.7.0_25\bin;C:\Users\Public\Documents\BeyondWallsXBRLValidator\;C:\Users\Public\Documents\BeyondWallsXBRL\;C:\SocketeQN\windowsandroid_root\system\bin;C:\SocketeQN\windowsandroid_root\system\lib
java.specification.name=Java Platform API Specification
java.class.version=50.0
sun.management.compiler=HotSpot Client Compiler
os.version=6.1
user.home=C:\Users\Beyond
user.timezone=Asia/Calcutta
java.awt.printerjob=sun.awt.windows.WPrinterJob
file.encoding=Cp1252
java.specification.version=1.6
java.class.path=D:\Spring3.0Examples\SystemPropertiesExample\bin;D:\SpringLibs\AdditionalJars\commons-logging-1.1.jar;D:\SpringLibs\SpringJars\spring-aop-3.2.8.RELEASE.jar;D:\SpringLibs\SpringJars\spring-aspects-3.2.8.RELEASE.jar;D:\SpringLibs\SpringJars\spring-beans-3.2.8.RELEASE.jar;D:\SpringLibs\SpringJars\spring-build-src-3.2.8.RELEASE.jar;D:\SpringLibs\SpringJars\spring-context-3.2.8.RELEASE.jar;D:\SpringLibs\SpringJars\spring-context-support-3.2.8.RELEASE.jar;D:\SpringLibs\SpringJars\spring-core-3.2.8.RELEASE.jar;D:\SpringLibs\SpringJars\spring-expression-3.2.8.RELEASE.jar;D:\SpringLibs\SpringJars\spring-framework-bom-3.2.8.RELEASE.jar;D:\SpringLibs\SpringJars\spring-instrument-3.2.8.RELEASE.jar;D:\SpringLibs\SpringJars\spring-instrument-tomcat-3.2.8.RELEASE.jar;D:\SpringLibs\SpringJars\spring-jdbc-3.2.8.RELEASE.jar;D:\SpringLibs\SpringJars\spring-jms-3.2.8.RELEASE.jar;D:\SpringLibs\SpringJars\spring-orm-3.2.8.RELEASE.jar;D:\SpringLibs\SpringJars\spring-oxm-3.2.8.RELEASE.jar;D:\SpringLibs\SpringJars\spring-struts-3.2.8.RELEASE.jar;D:\SpringLibs\SpringJars\spring-test-3.2.8.RELEASE.jar;D:\SpringLibs\SpringJars\spring-tx-3.2.8.RELEASE.jar;D:\SpringLibs\SpringJars\spring-web-3.2.8.RELEASE.jar;D:\SpringLibs\SpringJars\spring-webmvc-3.2.8.RELEASE.jar;D:\SpringLibs\SpringJars\spring-webmvc-portlet-3.2.8.RELEASE.jar
user.name=Beyond
java.vm.specification.version=1.0
java.home=D:\java\jre6
sun.arch.data.model=32
user.language=en
java.specification.vendor=Sun Microsystems Inc.
awt.toolkit=sun.awt.windows.WToolkit
java.vm.info=mixed mode, sharing
java.version=1.6.0_18
java.ext.dirs=D:\java\jre6\lib\ext;C:\Windows\Sun\Java\lib\ext
sun.boot.class.path=D:\java\jre6\lib\resources.jar;D:\java\jre6\lib\rt.jar;D:\java\jre6\lib\sunrsasign.jar;D:\java\jre6\lib\jsse.jar;D:\java\jre6\lib\jce.jar;D:\java\jre6\lib\charsets.jar;D:\java\jre6\classes
java.vendor=Sun Microsystems Inc.
file.separator=\
java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi
sun.io.unicode.encoding=UnicodeLittle
sun.cpu.endian=little
sun.desktop=windows
sun.cpu.isalist=pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86
Download as Zip 
Link to download
SystemPropertiesExample

Hints.
Click on File menu. then click "Download"
Best Lessons of "Spring 3.0 Examples"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details