MainController.java
package com.example.demo; import org.springframework.context.support.ClassPathXmlApplicationContext; public class MainController { public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); ISyain syain = context.getBean("testSyain", ISyain.class); System.out.println(syain.getHello()); context.close(); } }
applicationContext.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="testSyain" class="com.example.demo.Syain"></bean> </beans>
ISyain.java
package com.example.demo; public interface ISyain { public String getHello(); }
Syain.java
package com.example.demo; public class Syain implements ISyain { @Override public String getHello() { return "Hello World!"; } }
なるほどー