kunalkumar somani

Greenhorn
+ Follow
since Jul 13, 2011
kunalkumar likes ...
Eclipse IDE Spring Linux
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by kunalkumar somani

I'm not telling you that "storing the data in a singleton reference will take less memory than storing it elsewhere". I mean to say first you are creating one object it takes memory than the same object you are storing in another object tht increase the size of that object(where you stored) as well.

And please don't tell singleton is one of the most abused of the patterns.

Think about the perfomance please. If you are storing the object in context and whenever you want to read the property, first you have to get the object from the context, means you have to write getAttribute method and convert that object into Properties object and thn get the property.

You are increasing the line of code as well and compiler has to do more operation. In real time application client can not afford performance issue. And still you beleive that storing in context object is good idea please go ahead.
12 years ago
hi Srinivas,

You can use org.springframework.context.support.ReloadableResourceBundleMessageSource instead of org.springframework.context.support.ResourceBundleMessageSource.




hope works well....
12 years ago
Dear it takes same storage even i would say less storage but do you really think we need to store in application context? no and never please try to understand application object is available in the whole application, even if you dont required object you are storing in application context and tht way you are increasing the size of application context object and it is very costly.

Think on size like this way as well, first you are creating one object, this object also taking memory than you are storing in application context as well again, you are increasing the application context object size.

And singleton is not a bad idea. if you want to become a good programer and improve your application performance, you should use maximum java design pattern.

Singleton is one of the java design pattern.

12 years ago
Hi Marc van,

Bear Bibeault is correct this one is very old. And one more thing why you want to store in ServletContext, you are increasing the size of the object and ServletContext object is available in the whole application.

And still you want to load one time only and want to use in the whole application thn Create singleton object and load the property file in consturctor.



Hope works well....
12 years ago
Hi Fawad Ali,

By default it always singleton.

There are many ways to check your bean is singleton or not. For your confirmation if you want to check just create a Standalone application and load your configuration file from BeanFactory or ApplicationContext thn get your bean more thn one time using getBean() method.

And finally print object and check the address of that objects.It should be same. For example you can see below code in main method....


Resource resource = new FileSystemResource("com/spring/example/spring.cfg.xml");
BeanFactory factory = new XmlBeanFactory(resource);

Singleton singleton = (Singleton) factory.getBean("singleton");

Singleton singleton1 = (Singleton) factory.getBean("singleton");

System.out.println("Address 1=>"+singleton);
System.out.println("Address 2=>"+singleton1);

xml file has...

<bean id="singleton" class="com.example.Singleton">
</bean>
12 years ago
Hi Jason,

Yes, You are right.

Spring MVC framework is designed around a DispatcherServlet with configurable handler mappings, view resolution ant many things. The default handler is based on the @Controller and @RequestMapping annotations if you are using spring 3.0. In older version of spring you need to declare the bean in configuration file for request mapping.
12 years ago
Hi,

You need to configure message resouce bundle like below in xml file.

<bean id="resource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>filename without extension</value>
</list>
</property>
</bean>

<bean id="example" class="com.temp.Example">
<property name="messages" ref="messageSource"/>
</bean>

The File name which you provided that must be available in classpath. And because of that only you are getting this error "Can't find bundle for base name".

The Example class has below code

private MessageSource messages;

public void setMessages(MessageSource messages) {
this.messages = messages;
}

12 years ago