Skip to content

Instantly share code, notes, and snippets.

@lalyos
Created April 17, 2012 19:21
Show Gist options
  • Save lalyos/2408415 to your computer and use it in GitHub Desktop.
Save lalyos/2408415 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/org.springframework.core-3.0.4.RELEASE.jar"/>
<classpathentry kind="lib" path="lib/org.springframework.beans-3.0.4.RELEASE.jar"/>
<classpathentry kind="lib" path="lib/com.springsource.org.apache.commons.logging-1.1.1.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>spring-core</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

Readme

This is a temporary git repo

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean class="com.epam.training.spring.SysoutGreeting" id="greeting">
<constructor-arg type="java.lang.Integer" value="3"></constructor-arg>
<constructor-arg type="java.lang.String" value="Lets have a coffe"></constructor-arg>
</bean>
<bean class="com.epam.training.spring.SpringApp" >
<property name="greeting" ref="greeting" />
</bean>
</beans>
<?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="sysGreeting" class="com.epam.training.spring.SysoutGreeting"
p:message="Lets go to have some Lunch!" p:count="3" />
<bean id="loggerGreeting" class="com.epam.training.spring.LoggerGreeting"
p:message="Lets have a coffe break!" />
<bean name="greeting" class="com.epam.training.spring.PropertyFileGreeting"
p:fileName="greetings.properties" p:messagePropertyName="coffe.msg" init-method="init"/>
<bean id="multiGreeting" class="com.epam.training.spring.MultiGreeting" >
<property name="messages">
<list>
<value>Egy megerett a megy</value>
<value>Ketto, csipekbokor vesszo</value>
<value>harom</value>
</list>
</property>
</bean>
</beans>
<?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: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"
default-autowire="byName">
<bean class="com.epam.training.spring.SpringApp" />
</beans>
package com.epam.training.spring;
public class Bootstrap {
public static void main(String[] args) {
GreetingService greeting = new SysoutGreeting();
SpringApp app= new SpringApp();
app.setGreeting(greeting);
app.say();
}
}
gohome.msg=In 1 hour we can go home ...
coffe.msg=Lest have some coffee
lunch.msg=Lest have a lunch break
package com.epam.training.spring;
public interface GreetingService {
public void sayGreeting();
}
package com.epam.training.spring;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class LoggerGreeting implements GreetingService {
Log log = LogFactory.getLog(LoggerGreeting.class);
private String message;
@Override
public void sayGreeting() {
log.info(message);
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
handlers= java.util.logging.ConsoleHandler
.level= INFO
java.util.logging.ConsoleHandler.level = ALL
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
org.springframework.level = FINEST
package com.epam.training.spring;
import java.util.List;
public class MultiGreeting implements GreetingService {
private List<String> messages;
@Override
public void sayGreeting() {
for (String nextMessage : messages) {
System.out.println("multi: " + nextMessage);
}
}
public List<String> getMessages() {
return messages;
}
public void setMessages(List<String> messages) {
this.messages = messages;
}
}
package com.epam.training.spring;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
public class PropertyFileGreeting implements GreetingService {
private String fileName;
private String messagePropertyName;
private Properties props = new Properties();
public void init() {
try {
System.out.println("!!!\n!!!\n!!! reading file ...");
props.load(new FileInputStream(fileName));
String property = props.getProperty(messagePropertyName);
System.out.println("$$$ " + property);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void sayGreeting() {
String property = props.getProperty(messagePropertyName);
System.out.println("$$$ " + property);
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getMessagePropertyName() {
return messagePropertyName;
}
public void setMessagePropertyName(String messagePropertyName) {
this.messagePropertyName = messagePropertyName;
}
}
package com.epam.training.spring;
public class SpringApp {
private GreetingService greeting ;
public GreetingService getGreeting() {
return greeting;
}
public void setGreeting(GreetingService greeting) {
this.greeting = greeting;
}
public void say() {
greeting.sayGreeting();
}
}
package com.epam.training.spring;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;
public class SpringBootstrap {
/**
* @param args
*/
public static void main(String[] args) {
XmlBeanFactory providerFactory = new XmlBeanFactory(new FileSystemResource("beans-providers.xml"));
XmlBeanFactory factory = new XmlBeanFactory(new FileSystemResource("beans-setter.xml"), providerFactory);
SpringApp app = factory.getBean(SpringApp.class);
app.say();
app.say();
app.say();
}
}
package com.epam.training.spring;
public class SysoutGreeting implements GreetingService {
private String message = "Guten Morgen!";
private Integer count = 1;
public SysoutGreeting(){}
public SysoutGreeting(String message) {
super();
this.message = message;
}
public SysoutGreeting(String message, Integer count) {
super();
this.message = message;
this.count = count;
}
@Override
public void sayGreeting() {
for (int i = 0; i < count; i++) {
System.out.println(message);
}
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void setCount(Integer count) {
this.count = count;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment