- 1.新建一个空的Maven项目
- 2.导包
- 3.编写一个实体类
- 4.在resources目录下新建一个beans.xml
- 5. 测试
- 6.遇到的问题
spring-webmvc.jar
3.编写一个实体类org.springframework spring-webmvc 5.3.12
User实体类
package com.feng.pojo;
public class User {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void show(){
System.out.println("Hello,"+name);
}
}
4.在resources目录下新建一个beans.xml
编写beans.xml
5. 测试
import com.feng.pojo.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericGroovyApplicationContext;
public class MyTest {
public static void main(String[] args) {
ApplicationContext context = new GenericGroovyApplicationContext("beans.xml");
User hello = (User) context.getBean("hello");
hello.show();
}
}
6.遇到的问题
若运行时,报Caused by: java.lang.ClassNotFoundException: groovy.lang.GroovyObject错误,则需要导入
org.codehaus.groovy groovy 3.0.7



