Spring development environment construction - eclipse

foreword

Come on, come on, the installation of eclipse under Windows 10 is released.
Let's start to configure the environment happily.
So all the packages are uploaded to GitHub, take it yourself, hey hey, and download it from csdn, see the end of the article, try to download it from github

Install and configure the Java environment

重点: Don’t install eclipse first, you must configure the Java environment first, otherwise there will be problems (I don’t know what the problem is, anyway, it’s just weird.) Please see my blog for JAVA
environment configuration
. The configuration of Java is the same. This time I chose jdk11
java official website
a0

Install a web server

重点:Do not install eclipse yet

Apache-Tomcat, choose version 9 here, download, install and decompress

TomCat official website
a
1. After downloading, decompress the file as follows:
a
2. Enter the bin folder, click the startup.bat file, as shown in the figure below
insert image description here
3. Starting the Tomcat server will occupy a MS-DOS window and display the startup information. Closing the current MS-DOS window will shut down the Tomcat server.
s
4. Verify that the installation is successful

打开你的浏览器,随便,比如谷歌、火狐、微软一类的,在网址栏里输入 http://localhost:8080/
如果是下面第一幅图表示没有安装成功。
注意:上面的那个黑色窗口(TomCat启动窗口不要关闭)
成功了会显示下面第二幅图

insert image description here
a

install eclipse

eclipse is here

Eclipse official website

Other versions of Eclipse

1. Choose an adapted eclipse version, don't always think that the latest version is the best. There may be instability problems, and don't get too old.
You can download the latest version directly below (not recommended
a
2. Enter the version download, here I choose 2019-06
insert image description here
3. Select the first one, download eclipseEE
insert image description here
4. After downloading, unzip to the custom directory, double-click eclipse
insert image description here
5. Customize workspace insert image description here
6.eclipse installation is complete
a

Integrate Tomcat

1. Select window->preferences
insert image description here

2. Select server->runtime environments->add
insert image description here
3. Load the tomcat location that you have successfully installed after decompression, and select version 9, because the version number you installed is it
a
a

spring download

Spring official website
After the Spring official website is upgraded, it is recommended to download through Maven and Gradle.

When using the Spring framework to develop applications, in addition to referencing the JAR package of Spring itself, you also need to refer to the JAR package of commons.logging. emmmmm,我全放在zip包里面了,这里就不说怎么用Gradle下载了,我也没去研究,哈哈哈,可能类似于Android,compile一下或者implementation一下

1.Spring的JAR包
2.commons.logging的JAR包

s

s

Create my first Spring program

啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊
eclipse好难用,eclipse好难用,eclipse好难用,eclipse好难用,eclipse好难用
eclipse好难用,eclipse好难用,eclipse好难用,eclipse好难用,eclipse好难用
eclipse好难用,eclipse好难用,eclipse好难用,eclipse好难用,eclipse好难用

1. Use eclipse to create a project named ch1_1, as follows
insert image description here
2. Copy the four basic jar packages and common logging of spring to the WEB-INF/lib folder.

a
3. Then create an interface, create a configuration file, and write code.
Let’s be more specific,
select window->show view->projectExplore, and then you can see the following picture, and then copy the above file to WebContent->Web-INF->lib, just right-click lib, Then paste
a
4. Then we start to write code, right mouse button src under JAVA Resource, select new, package, the name is dao

insert image description here
5. Right-click dao to create an interface called TestDao
a

6. Write the following code

package dao;
public interface TestDao {
    
    
	public void sayHello();
}

a
7. Same as 5, (just select class) create a class named TestDaoImpl and
the code is as follows

package dao;

public class TestDaoImpl implements TestDao{
    
    
	@Override
	public void sayHello() {
    
    
		System.out.println("Hello,go to sleep!");
	}
}

8. Create the configuration file applicationContext.xml
Right-click src, new OtherFile, select the xml file
a
a
a
9. Click source at the bottom of applicationContext.xml, and write the following code:

<?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">
	<!-- 将指定类TestDaoImpl配置给Spring,让Spring创建其实例 -->
	<bean id="test" class="dao.TestDaoImpl" />
</beans>

a
10. Create a test class
Create a test package under src, that is, package
and then create a Test class under the test package
a

package test;

import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import dao.TestDao;
public class Test {
    
    
	public static void main(String[] args) {
    
    
		//初始化Spring容器ApplicationContext,加载配置文件
				@SuppressWarnings("resource")
				ApplicationContext appCon = 
		new ClassPathXmlApplicationContext("applicationContext.xml");
				//通过容器获取test实例
				TestDao tt = (TestDao)appCon.getBean("test");
				tt.sayHello();
	}

}

11. Run the code, select run as java application
insert image description here
12. Console output results
insert image description here

all resources

https://github.com/Nianf/Experiment-data/tree/main/softwareData
Unexpectedly, github can’t finish uploading because the package is too big, so I only uploaded part of it. If you want, please private message me
or leave yours in the comment area Email
This is the csdn resource, which contains all the packages of the above experiments all-packages

Guess you like

Origin blog.csdn.net/qq_43738932/article/details/120301928