Skip to content

Instantly share code, notes, and snippets.

@NikhilAshodariya
Last active November 25, 2017 07:05
Show Gist options
  • Select an option

  • Save NikhilAshodariya/afd20b14112a50f035f779eeec9b5be4 to your computer and use it in GitHub Desktop.

Select an option

Save NikhilAshodariya/afd20b14112a50f035f779eeec9b5be4 to your computer and use it in GitHub Desktop.
package in.blogspot.codewithnikhil.beans;
import java.net.URL;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Run
{
public static void main(String[] args)
{
URL resource = Run.class.getResource("..");
ApplicationContext context = new ClassPathXmlApplicationContext(resource+"resources/spring.xml");
Triangle t = (Triangle) context.getBean("tri");
t.paint();
System.out.println(t.getTriType());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<bean id="tri" class="in.blogspot.codewithnikhil.beans.Triangle">
<property name="triType" value="Scalene Triangle"></property>
</bean>
</beans>
package in.blogspot.codewithnikhil.beans;
public class Triangle
{
private String triType;
public void paint()
{
System.out.println(getTriType() + " Drawn");
}
public String getTriType()
{
return triType;
}
public void setTriType(String triType)
{
this.triType = triType;
}
@Override
public String toString()
{
return "Triangle{" + "triType=" + triType + '}';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment