Skip to content
Browse files

using the @Component with @Value + Property placeholder

  • Loading branch information...
1 parent 158d2da commit a41aee0b611edb51c40d41dccdaf6e93a1ba1583 @lalyos committed
View
3 src/main/java/com/epam/training/spring/I18NGreeting.java
@@ -5,6 +5,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
@@ -14,7 +15,9 @@
private ApplicationContext ctx;
+ @Value("${msg.key}")
private String messageName;
+ @Value("${greeting.locale}")
private Locale locale;
private Logger logger = LoggerFactory.getLogger(I18NGreeting.class);
View
2 src/main/resources/META-INF/spring/app-context.xml
@@ -7,8 +7,6 @@
<context:component-scan base-package="com.epam" />
<context:property-placeholder location="application.properties"/>
- <bean name="greeting" class="com.epam.training.spring.I18NGreeting"
- p:messageName="greet.msg" p:locale="${greeting.locale}"/>
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
View
3 src/main/resources/application.properties
@@ -1 +1,2 @@
-greeting.locale=es
+greeting.locale=hu
+msg.key=lunch.msg
View
4 src/main/resources/messages.properties
@@ -1 +1,3 @@
-greet.msg=Lets have a lunch break!
+lunch.msg=Lets have a lunch break!
+coffe.msg=lets have a coffee
+toilet.msg=lets have a short brake
View
4 src/main/resources/messages_es.properties
@@ -1 +1,3 @@
-greet.msg=vamanos burritos!
+lunch.msg=vamanos burritos!
+coffe.msg=coffesito porfavor
+toilet.msg=wc
View
4 src/main/resources/messages_hu.properties
@@ -1 +1,3 @@
-greet.msg=zabaljunk!
+lunch.msg=pakoljunk az arclemez moge
+coffe.msg=kavezzunk
+toilet.msg=puderrezuk be az orrunkat

0 comments on commit a41aee0

Please sign in to comment.
Something went wrong with that request. Please try again.