実際の戦闘へのJavaEEフレームワーク統合開発エントリ:Spring + SpringMVC + MyBAtis(マイクロクラスバージョン)-コード演習の最初の章

純粋なハンドノック、ご支援ありがとうございます

	使用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>

運転結果

ここに画像の説明を挿入します

おすすめ

転載: blog.csdn.net/qq_41827511/article/details/115030826