Permalink
Browse files

adding the simple code.

  • Loading branch information...
1 parent 2071e5b commit 9e744c5e7f39dbe1cceb98e85c5c80da3c0d2bc8 Josh Long committed Oct 13, 2011
Showing with 113 additions and 0 deletions.
  1. +47 −0 pom.xml
  2. +39 −0 src/main/java/HelloWorldGreeter.java
  3. +27 −0 src/main/java/Main.java
View
@@ -0,0 +1,47 @@
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.springsource.demonstrations</groupId>
+ <artifactId>simplest-spring-application-ever</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0.0-SNAPSHOT</version>
+ <name>simplest spring application ever</name>
+ <url>http://www.github.com/joshlong</url>
+
+ <properties>
+ <spring.framework.version>3.0.6.RELEASE</spring.framework.version>
+ </properties>
+ <dependencies>
+
+ <dependency>
+ <groupId>cglib</groupId>
+ <artifactId>cglib-nodep</artifactId>
+ <version>2.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>${spring.framework.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
+
@@ -0,0 +1,39 @@
+import org.springframework.beans.factory.InitializingBean;
+
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * Simple bean.
+ */
+public class HelloWorldGreeter implements InitializingBean {
+
+ private Map<String, String> salutations;
+
+ public HelloWorldGreeter(Map<String, String> sals) {
+ this.salutations = sals;
+ }
+
+ public String greet(Locale lo) {
+ String language = lo.getLanguage().toLowerCase();
+ for (String k : this.salutations.keySet()) {
+ if (language.contains(k)) {
+ return (this.salutations.get(k));
+ }
+ }
+ return null;
+ }
+
+ public String greet() {
+ Locale locale = Locale.getDefault();
+ return greet(locale);
+ }
+
+
+ public void afterPropertiesSet() throws Exception {
+ Locale[] locales = {new Locale("IT"), new Locale("FR"), new Locale("ES"), new Locale("EN")};
+ for (Locale l : locales) {
+ System.out.println(l.toString() + " : " + greet(l));
+ }
+ }
+}
@@ -0,0 +1,27 @@
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class Main {
+
+ @Configuration
+ public static class HelloWorldConfiguration {
+
+ @Bean
+ public HelloWorldGreeter greeter() {
+ Map<String, String> salutations = new HashMap<String, String>();
+ salutations.put("en", "Hello, world!");
+ salutations.put("it", "Buongiorno a tutto il mondo!");
+ salutations.put("fr", "bonjour a tout le monde!");
+ salutations.put("es", "buenas dias a todo el mundo!");
+ return new HelloWorldGreeter(salutations);
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ new AnnotationConfigApplicationContext(HelloWorldConfiguration.class);
+ }
+}

0 comments on commit 9e744c5

Please sign in to comment.