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,注解的作用就是用于 ...
随机推荐
- [原][Java]eclipse 修改自动提示
下载 jar 链接:http://files.cnblogs.com/files/z5337/org.eclipse.jface.text_3.7.2.v20111213-1208.zip 或者这个: ...
- Hive常用函数
字符串函数 字符串长度函数:length 语法: length(string A) 返回值: int 说明:返回字符串A的长度 举例: hive> select length(‘abcedfg’ ...
- 修改jvm xms参数
http://hi.baidu.com/200770842223/item/9358aad4f3194e1a20e2501b http://www.cnblogs.com/mingforyou/arc ...
- SQL Server修改表结构后批量更新所有视图
最近修改了数据库表结构,数据同步的时候出了问题,发现很多数据明明已经修改,但是通过视图筛选出来的还是原来的数据,所以怀疑应该是视图缓存了数据,在园子里找到下面的博文,在这里做个记录备忘. 原文链接:h ...
- go语言数组与切片比较
一.数组 与其他大多数语言类似,Go语言的数组也是一个元素类型相同的定长的序列. (1)数组的创建. 数组有3种创建方式:[length]Type .[N]Type{value1, value2, . ...
- gen_projective_mosaic(Halcon例子)
* This example program shows how several images of a PCB can be combined * into a large mosaic image ...
- .NET和UNITY版本问题
亲测:unity5.5之前:通过VS工程属性查看.NET版本为3.5, 对应unity中没有可查看的项,只有一个Api Compatibility level 是.net subset2.0,看名字, ...
- S 导客户主数据 及更新销售团队、组织、品牌
一.导入客户主表(INSERT) EXCEL模板 [Public] ConnectString=host="siebel://10.10.0.46:2321/HC_CRM/SMObjMgr_ ...
- UNITY中有Timer
using UnityEngine; using System.Collections; using System.Timers; public class NewBehaviourScript : ...
- WebService超时
1.web.config配置,<system.web></system.web>里面增加:<httpRuntime maxRequestLength="1024 ...