【Basic computer】-----Java Spring :Injection Objects (注入对象篇)
来源:互联网 发布:java开发框架 编辑:程序博客网 时间:2024/05/17 03:37
Java Spring -----Injection Objects
【Abstract】
I am going to give you a demo and a view help you to understand it easily. Spring Framework is a Java platform that provides comprehensive infrastructure support for developing Java applications. Spring handles the infrastructure so you can focus on your application.
As we know ,long time ago ,we use about MVC ,up to right now, MVC is upgrade as usual like the society is update rapidly . Controller separate two as “Front Controller” and ”Controller”, Front Controller is going to deal with the model view , while “Controller” resolve the business logic.
As we can see in the drawing, incoming request message send to “Front Controller”,which Front Controller delegate the request to “Controller”, after that, Controller got the DB and send the business logic to Model,,,,,,,
So, what is the code,can you show off? Of course, the following is the code:
【DrawingApp.java】
package Daniel.tgb;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class DrawingApp { public static void main(String[] args){//Tringle triangle =new Tringle();//BeanFactory factory=new XmlBeanfacotry(new FileSystemResource("spring.xml")); ApplicationContext context=new ClassPathXmlApplicationContext("spring.xml"); Triangle triangle =(Triangle)context.getBean("triangle"); triangle.draw(); } }
【Point.java】
package Daniel.tgb;public class Point { private int x; private int y; public int getX() {return x;}public void setX(int x) {this.x = x;}public int getY() {return y;}public void setY(int y) {this.y = y;}}
【Triangle.java】
package Daniel.tgb;public class Triangle { private Point pointA; private Point pointB; private Point pointC; public Point getPointA() {return pointA;}public void setPointA(Point pointA) {this.pointA = pointA;}public Point getPointB() {return pointB;}public void setPointB(Point pointB) {this.pointB = pointB;}public Point getPointC() {return pointC;}public void setPointC(Point pointC) {this.pointC = pointC;}public void draw() {// TODO Auto-generated method stubSystem.out.println("PointA=("+getPointA().getX()+","+getPointA().getY()+")");System.out.println("PointB=("+getPointB().getX()+","+getPointB().getY()+")");System.out.println("PointC=("+getPointC().getX()+","+getPointC().getY()+")"); } }
【spring.xml】
<?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.xsd"> <bean id="triangle" class="Daniel.tgb.Triangle"> <property name="pointA" ref="Point1"/> <property name="pointB" ref="Point2"/> <property name="pointC" ref="Point3"/> </bean> <bean id="Point1" class="Daniel.tgb.Point"> <property name="x" value="0"/> <property name="y" value="0"/> </bean> <bean id="Point2" class="Daniel.tgb.Point"> <property name="x" value="-20"/> <property name="y" value="0"/> </bean> <bean id="Point3" class="Daniel.tgb.Point"> <property name="x" value="0"/> <property name="y" value="20"/> </bean> </beans>
Here is the results :
Impression:Java applications -- a loose term that runs the gamut from constrained applets to n-tier server-side enterprise applications -- typically consist of objects that collaborate to form the application proper. Thus the objects in an application have dependencies on each other.
1 0
- 【Basic computer】-----Java Spring :Injection Objects (注入对象篇)
- java spring Injecting Objects 注入对象
- spring依赖注入(dependency injection)
- PHP Object Injection(PHP对象注入)
- Spring之对象依赖关系(依赖注入Dependency Injection)
- Spring 集合注入 [ Collection Injection ]
- Spring依赖注入(dependency injection)
- 码农小汪-spring框架学习之3-spring Method injection(方法注入 ) Lookup method injection
- Spring的核心--依赖注入(Dependency Injection)
- Spring学习笔记(二)依赖注入Dependency Injection
- Spring之注入类型(DI:dependency injection)
- 注入攻击(Injection Flaws)
- 依赖注入(Dependency Injection)
- Command Injection(命令行注入)
- SQL注入(SQL Injection)
- IOC_Spring注入方式(injection)
- 依赖注入(Dependence Injection)
- Spring笔记之七(Types of Injection) Spring的三种依赖注入实现类型
- nyoj722 数独
- SpringMVC + redis缓存
- Unity3D关于VR的Demo(一)
- Java 之 线程join
- 并查集 入门 以及状态压缩 C
- 【Basic computer】-----Java Spring :Injection Objects (注入对象篇)
- 今日头条 最大映射
- 响应式布局
- 关于Android Studio里的Gradle,你所需要知道的都在这里了
- 安卓版本更新
- 设计模式_JAVA_策略模式
- hdoj 1969 Pie 【二分】
- SCI
- Xcode是如何诞生的?