Spring下载与初次使用一些问题
现在web程序基本上都用spring,有时像一些不是专门做java开发的人,有时想学习spring或者用spring做个练习项目,找不到spring下载入口是一个尴尬的事。有时百度到的是过时的,在次记录下载过程。
Spring下载
参考博客:http://blog.csdn.net/saszyl/article/details/70148303
|
基本步骤 1:进入spring的github: https://github.com/spring-projects/spring-framework 2:找到以下两个位置点击连接进入,http://repo.spring.io就是spring的下载页面入口,记住。
在左侧的 Artifact Repository Browser 依次点击 libs-release-local --> org/ --> springframework --> spring ,选择自己需要的版本下载
方法二:
方法三:
4:Spring目录结构与说明
|
Spring的相关jar报下载与加入
|
1初次使用把libs下的所有jar加入了
|
相关配置与一个请求测试
|
解决方案1 https://jingyan.baidu.com/article/90808022c495d9fd91c80f15.html 解决方法2: 右键项目名称-》Java EE Tools-》Generate Deployment descriptor stub即可生成web.xml文件。
2:web.xml配置 <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 当前servlet的参数信息 --> <init-param> <param-name>contextConfigLocation</param-name> <!-- 在DispatcherServlet的初始化过程中,框架会在web应用的 WEB-INF文件夹下寻找名为[servlet-name]-servlet.xml 的配置文件,生成文件中定义的bean --> <!-- 或者 /web-inf/springmvc-config.xml --> <param-value>classpath*:/springMVC.xml</param-value> </init-param>
<!-- 在web应用启动的时立即加载 servlet--> <load-on-startup>1</load-on-startup> </servlet> <!-- servlet映射声明 --> <servlet-mapping> <!-- 请求对应的servlet的名称 --> <servlet-name>springmvc</servlet-name> <!-- 监听当前域的所有请求 --> <url-pattern>/</url-pattern> </servlet-mapping>
SpringMVC.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" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <!-- 自动扫描的包名 --> <context:component-scan base-package="com.app,com.core" ></context:component-scan> <bean name="/hello" class="com.sxt.controller.helloController"></bean> <!-- 映射器 --> <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"></bean> <!-- 适配器 --> <bean class = "org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"></bean> <!-- 默认的注解映射的支持 --> <mvc:annotation-driven /> <!-- 视图解释类 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"></bean> </beans>
|
eclipse开发servlet,HttpServletRequest报红叉解决方案
|
参考文章:https://www.cnblogs.com/hjchoset/p/6031547.html 解决方法:鼠标右击项目工程——》Build Path——》点击comfigure Build Path进入----->选择java Bulid Path------>在左边点击Libraries--------->选择Add Librar
就ok了 |