troubleshooting Question

spring internalization

Avatar of gudii9
gudii9Flag for United States of America asked on
JavaJSPJava EE
2 Comments1 Solution584 ViewsLast Modified:

I am running below example on spring internalization
circle class is


import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
public class Circle implements Shape {
private Point center;
private MessageSource messageSource;
	public MessageSource getMessageSource() {
	return messageSource;
public void setMessageSource(MessageSource messageSource) {
	this.messageSource = messageSource;
	public Point getCenter() {
	return center;
//	@Autowired
//	@Qualifier("circleRelated")
public void setCenter(Point center) { = center;
	public void draw() {
		// TODO Auto-generated method stub
		System.out.println(this.messageSource.getMessage("", null,"default drwning msg",null));
		System.out.println(this.messageSource.getMessage("drawing.point",new Object[] {center.getX(),center.getY()},"default drwning msg",null));
	//	System.out.println("circle point ("+center.getX()+",,,"+center.getY()+")");

	//System.out.println(this.messageSource.getMessage("greeting", null,"default grtng",null));
//	}
public void initializeCircle(){
	System.out.println("in circle initialize");
public void destroyCircle(){
	System.out.println("in circle destroy");

client class is


import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;

public class DrawingAppObj {

	 * @param args
	public static void main(String[] args) {
		//	Triangle triangle=new Triangle();
		//	triangle.draw();

//		BeanFactory factory=new XmlBeanFactory(new FileSystemResource("spring.xml"));
//		AbstractApplicationContext context=new ClassPathXmlApplicationContext("spring.xml");
//		context.registerShutdownHook();
//		Trianglebj trianglebj	=(Trianglebj) context.getBean("triangle");
//	//	Trianglebj trianglebj	=(Trianglebj) context.getBean("triangle-alias");
//		trianglebj.draw();
	//	Circle circle	=(Circle) context.getBean("circle");
		//	Trianglebj trianglebj	=(Trianglebj) context.getBean("triangle-alias");
//		ApplicationContext context=new ClassPathXmlApplicationContext("spring.xml");
		AbstractApplicationContext context=new ClassPathXmlApplicationContext("spring.xml");
		Shape shape=(Shape)context.getBean("circle");
//		Shape shape=(Shape)context.getBean("triangle");
		//	System.out.println(context.getMessage("greeting", null,"default grtng",null));


point class is


public class Point {
private int x;
public int getX() {
	return x;
public void setX(int x) {
	this.x = x;
public int getY() {
	return y;
public void setY(int y) {
	this.y = y;
private int y;


shape interface is


public interface Shape {
public void draw();

triangle class is


import java.util.List;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class Trianglebj implements Shape{

private Point pointA;
private Point pointB;
private Point pointC;
//private ApplicationContext context=null;

	public void draw(){

System.out.println("triangle draw");
	//	System.out.println(getType()+"triangle drawed"+getHeight());


	public Point getPointA() {
		return pointA;

	public void setPointA(Point pointA) {
		this.pointA = pointA;

	public Point getPointB() {
		return pointB;

	public void setPointB(Point pointB) {
		this.pointB = pointB;

	public Point getPointC() {
		return pointC;

	public void setPointC(Point pointC) {
		this.pointC = pointC;

	public void myInit(){
		System.out.println("myinit() beans init called for triangle");	
	public void cleanUp(){
		System.out.println("cleanUp() beans cleanUp called for triangle");	

//	@Override
//	public void destroy() throws Exception {
//		// TODO Auto-generated method stub
//		System.out.println("destroy of DisposableBean called");
//	}
//	@Override
//	public void afterPropertiesSet() throws Exception {
//		// TODO Auto-generated method stub
//		System.out.println("afterPropertiesSet of initializing bean called");
//	}


mymessages property file is

greeting=hi all circlee
drawing.point=circle point ({0},{1})

spring xmnl is

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""

<bean id="triangle" class="" autowire="byName">
<property name="pointA" ref="pointA"/>
<property name="pointB" ref="pointB"/>
<property name="pointC" ref="pointC"/>
</bean> -->

<bean id="pointA" class="">
<qualifier value="circleRelated"/>
<property name="x" value="0"/>
<property name="y" value="0"/>

<bean id="pointB" class="">
<property name="x" value="20"/>
<property name="y" value="0"/>

<bean id="center" class="">
<property name="x" value="-200"/>
<property name="y" value="0"/>

<!-- <bean id="circle" class="">
<property name="center" ref="pointA"/>

</bean> -->
<bean id="messageSource" class="">
<property name="basenames">
<!-- <bean class=""/> -->
<bean class=""/> 
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
<property name="location" value=""></property>
<!-- <bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/> -->
<!-- <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/> -->

	<context:component-scan base-package=""/>

points property file is


output is

Apr 1, 2013 10:46:50 AM prepareRefresh
INFO: Refreshing startup date [Mon Apr 01 10:46:50 CDT 2013]; root of context hierarchy
Apr 1, 2013 10:46:50 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [spring.xml]
Apr 1, 2013 10:46:50 AM loadProperties
INFO: Loading properties file from class path resource []
my bean factory post processor invoked
Apr 1, 2013 10:46:50 AM preInstantiateSingletons
INFO: Pre-instantiating singletons in defining beans [pointA,pointB,center,messageSource,,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,circle]; root of factory hierarchy
in circle initialize
=drawing circlee
circle point (-200,0)
in circle destroy

my question is how do i extend this application to support locale. Let us say if i want to support spanish also along with english how do i make chnages to reflect that.

Please advise. Any ideas, resources, sample code highly appreciated. thanks in advance
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros