1.定义接口

public interface IsomeService {
   void doSome();
}

2.实现接口

public class SomeServiceImpl implements IsomeService {


public void doSome() {
System.out.println("执行doSome()方法");

}


public SomeServiceImpl() {
System.out.println("构造方法");
// TODO Auto-generated constructor stub
}

}

3.定义测试类

public class MyTest {
@Test


public void test() {
// ClassPathXmlApplicationContext("applicationContest.xml")类路径下
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContest.xml");
IsomeService service = (IsomeService) ac.getBean("someService");
service.doSome();
}

4.导入jar包     (我这里是根据老师的视频而学习,具体的jar包更新的快在官网下载。)

 第一个Spring程序    beans context.core.sel四个jar包

创建xml文件,最好命名为applicationConText , 后面有这个方法。

这个XML配置文件约束从Spring框架的如下文件中可以找到:

\docs\spring-framework-reference\html\xsd-configuration.html

第一个Spring程序




第一个Spring程序

执行结果第一个Spring程序

相关文章:

  • 2021-06-02
  • 2018-02-25
  • 2021-11-18
  • 2021-09-23
  • 2021-12-09
  • 2021-09-14
  • 2021-10-12
  • 2021-08-14
猜你喜欢
  • 2021-02-24
  • 2020-01-04
  • 2018-01-17
  • 2021-10-30
  • 2021-07-02
  • 2021-05-20
相关资源
相似解决方案