发布时间:2022-09-05 03:00
使用eclipse编写,工程目录结构如下:
目录结构
其中使用的Spring核心jar放在WEB-INF的lib目录下
TestDao.java
package dao;
public interface TestDao {
public void sayHello();
}
TestDaoImpl.java
package dao;
public class TestDaoImpl implements TestDao {
@Override
public void sayHello() {
// TODO Auto-generated method stub
System.out.println("Hello,Study hard!");
}
}
Test.java
package test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.core.io.FileSystemResource;
import dao.TestDao;
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub
/*初始化Spring容器,加载配置文件
BeanFactory工厂
BeanFactory beanFac=new XmlBeanFactory(new FileSystemResource("C:\\Users\\gao\\Desktop\\Spring环境搭建\\ch1\\src\\applicationContext.xml"));
TestDao tt=(TestDao)beanFac.getBean("test");
*/
//ApplicationContext appCon=new ClassPathXmlApplicationContext("applicationContext.xml");
//TestDao tt=(TestDao)appCon.getBean("test");
ApplicationContext appcon=
new FileSystemXmlApplicationContext("C:\\\\Users\\\\gao\\\\Desktop\\\\Spring环境搭建\\\\ch1\\\\src\\\\applicationContext.xml");
TestDao tt=(TestDao)appcon.getBean("test");
tt.sayHello();
}
}
application.xml
package test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.core.io.FileSystemResource;
import dao.TestDao;
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub
/*初始化Spring容器,加载配置文件
BeanFactory工厂
BeanFactory beanFac=new XmlBeanFactory(new FileSystemResource("C:\\Users\\gao\\Desktop\\Spring环境搭建\\ch1\\src\\applicationContext.xml"));
TestDao tt=(TestDao)beanFac.getBean("test");
*/
//ApplicationContext appCon=new ClassPathXmlApplicationContext("applicationContext.xml");
//TestDao tt=(TestDao)appCon.getBean("test");
ApplicationContext appcon=
new FileSystemXmlApplicationContext("C:\\\\Users\\\\gao\\\\Desktop\\\\Spring环境搭建\\\\ch1\\\\src\\\\applicationContext.xml");
TestDao tt=(TestDao)appcon.getBean("test");
tt.sayHello();
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>ch1</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
IDEA创建maven项目遇到Dependency ‘junit:junit:4.12‘ not found
【Kubernetes 系列】 一文带你吃透 K8S 中Pod 的生命周期
解决vue中数据更新视图不更新问题this.$set()方法
Spring Cloud:Eureka,Ribbon,Hystrix,Feign,GateWay,Config
STM32 伺服电机 指令脉冲+方向位置控制模式 主从定时器 实现PWM脉冲数精确控制
【Pytorch->ONNX->NCNN->NCNNfp16->vs编译】Windows NCNN部署