IDEA配置spring
大半天都在看spring,以前总是看不下去,这次慢慢来,慢慢看。
看那些基础的,倒是还不错。好多都是关于helloworld的,写完helloworld,觉得不怎么形象。于是写了动物,作为接口。

(1)动物接口方法:move(),say()。
(2)cat和dog ,实现接口。
package Animal; /**
* Created with IntelliJ IDEA.
* User: wang
* Date: 13-10-22
* Time: 下午5:12
* To change this template use File | Settings | File Templates.
*/
public class Cat implements Animal {
@Override
public void move() {
//To change body of implemented methods use File | Settings | File Templates.
System.out.println("4 legs");
} @Override
public void say() {
//To change body of implemented methods use File | Settings | File Templates.
System.out.println("miao miao");
}
}
(3)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="cat" class="Animal.Cat" ></bean>
<bean id="dog" class="Animal.Dog"></bean>
<bean id="bird" class="Animal.Bird">
<constructor-arg index="0" value="gegegege"></constructor-arg>
<constructor-arg index="1" value="gogogo"></constructor-arg>
</bean>
</beans>
xml里面,有个constructor-arg ,这个是bird里面,构造方法参数。
(4) Bird.java
package Animal; /**
* 带有参数的spring bean
* Created with IntelliJ IDEA.
* User: wang
* Date: 13-10-22
* Time: 下午6:09
* To change this template use File | Settings | File Templates.
*/
public class Bird implements Animal { private String message;
private String movess;
public Bird(String message,String movess){
this.message=message;
this.movess=movess;
} @Override
public void say() {
//To change body of implemented methods use File | Settings | File Templates.
System.out.println(message);
} @Override
public void move() {
//To change body of implemented methods use File | Settings | File Templates.
System.out.println(movess);
}
}
构造方法里面,有两个参数,xml对应的有设置。
(5) 然后测试一下,ATest.java
package Animal; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; /**
* Created with IntelliJ IDEA.
* User: wang
* Date: 13-10-22
* Time: 下午5:19
* To change this template use File | Settings | File Templates.
*/
public class ATest {
public static void main(String args[]){
ApplicationContext applicationContext=new ClassPathXmlApplicationContext("spring-config.xml");
Animal animal=applicationContext.getBean("cat",Cat.class);
animal.say();
animal.move();
Animal animal1=applicationContext.getBean("dog",Dog.class);
animal1.say();
animal1.move();
Animal animal2=applicationContext.getBean("bird",Bird.class);
animal2.say();
animal2.move();
}
}
这突出了面向接口编程了。
总之还不错,看了一些,挺不错的。
IDEA配置spring的更多相关文章
- 如何用Java类配置Spring MVC(不通过web.xml和XML方式)
DispatcherServlet是Spring MVC的核心,按照传统方式, 需要把它配置到web.xml中. 我个人比较不喜欢XML配置方式, XML看起来太累, 冗长繁琐. 还好借助于Servl ...
- 事务管理(下) 配置spring事务管理的几种方式(声明式事务)
配置spring事务管理的几种方式(声明式事务) 概要: Spring对编程式事务的支持与EJB有很大的区别.不像EJB和Java事务API(Java Transaction API, JTA)耦合在 ...
- Spring 4 官方文档学习(十一)Web MVC 框架之配置Spring MVC
内容列表: 启用MVC Java config 或 MVC XML namespace 修改已提供的配置 类型转换和格式化 校验 拦截器 内容协商 View Controllers View Reso ...
- 更加优雅地配置Spring Securiy(使用Java配置和注解)
Spring Security 借助一系列Servlet Filter 来提供安全性功能,但是借助Spring的小技巧,我们只需要配置一个Filer就可以了,DelegatingFilterProxy ...
- web.xml中配置Spring中applicationContext.xml的方式
2011-11-08 16:29 web.xml中配置Spring中applicationContext.xml的方式 使用web.xml方式加载Spring时,获取Spring applicatio ...
- JAVAEE——spring02:使用注解配置spring、sts插件、junit整合测试和aop演示
一.使用注解配置spring 1.步骤 1.1 导包4+2+spring-aop 1.2 为主配置文件引入新的命名空间(约束) 1.3 开启使用注解代替配置文件 1.4 在类中使用注解完成配置 2.将 ...
- eclipse中配置spring环境
初识Spring框架 1.简单使用 eclipse中配置Spring环境,如果是初学的话,只需要在eclipse中引入几个jar包就可以用了, 在普通java project项目目录下,建一个lib文 ...
- 配置spring的监听器 让spring随项目的启动而启动
<!-- 配置spring的监听器 让spring随项目的启动而启动 --> <listener> <listener-class>org.springframew ...
- 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建三:配置spring并测试
这一部分的主要目的是 配置spring-service.xml 也就是配置spring 并测试service层 是否配置成功 用IntelliJ IDEA 开发Spring+SpringMVC+M ...
- 注解配置spring
1.为什么使用注解配置Spring基于注解配置的方式也已经逐渐代替xml.这个是不可逆的潮流,所以我们必须要掌握使用注解的方式配置Spring 总结:(1)使用注解配置Spring,注解的作用就是用于 ...
随机推荐
- PHP外部调用网站百度统计数据的方法详解
目的:外部调用网站的百度统计(tongji.baidu.com)数据. 条件:1.具备调用目标网站的百度统计平台管理权限 2.PHP环境支持curl函数. 原理:同PHP小偷程序原理,通过curl函数 ...
- Thinkphp 查询条件 and 和 or同时使用即复合查询
thinkphp 3.2快捷查询OR查询&分割表示AND查询讲解 快捷查询方式是一种多字段查询的简化写法,可以进一步简化查询条件的写法,在多个字段之间用|分割表 ...
- mongodb聚合 group
MongoDB中聚合(aggregate)主要用于处理数据(诸如统计平均值,求和等),并返回计算后的数据结果.有点类似sql语句中的 count(*). 基本语法为:db.collection.agg ...
- opencv:级联分类器训练(cascade classifier training)(两个分类器的区别)
# 介绍 级联分类器包括两个工作阶段:训练(traning),检测(detection).检测阶段在文档<objdetect module of general OpenCV documenta ...
- FireFox add dict
1.Firefox add add-ons: inline translation 2.https://login.live.com/login.srf?wa=wsignin1.0&wtrea ...
- window.btoa()方法;使字符编码成base64的形式
atob() 函数能够 解码 通过base-64编码的字符串数据.相反地, btoa() 函数能够从二进制数据“字符串” 创建 一个base-64编码的ASCII字符串.
- Eclipse安装Freemarker Editor插件
在下面网址里下载freemarker-ide: http://sourceforge.net/projects/freemarker-ide/files/ 下载完成后后解压,由于该IDE里面的free ...
- 归纳整理Linux下C语言常用的库函数----文件操作
在没有IDE的时候,记住一些常用的库函数的函数名.参数.基本用法及注意事项是很有必要的. 参照Linux_C_HS.chm的目录,我大致将常用的函数分为一下几类: 1. 内存及字符串控制及操作 2. ...
- LevelDB Cache机制
[LevelDB Cache机制] 对于levelDb来说,读取操作如果没有在内存的memtable中找到记录,要多次进行磁盘访问操作.假设最优情况,即第一次就在level 0中最新的文件中找到了这个 ...
- android 读取json数据(遍历JSONObject和JSONArray)(转)
public String getJson(){ String jsonString = "{\"FLAG\":\"flag\",\"MES ...