最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

maven插件spring-boot-starter-tomcat的使用方式

 更新時(shí)間:2022年07月08日 14:41:10   作者:金霖海  
這篇文章主要介紹了maven插件spring-boot-starter-tomcat的使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

tomcat內(nèi)嵌到web項(xiàng)目中

將tomcat 內(nèi)嵌到 web項(xiàng)目中,這樣可以直接運(yùn)行 webapp項(xiàng)目。

不需要再部署到額外的tomcat,直接就可以運(yùn)行了。

1.pom.xml 配置

    <plugins>
      <plugin>
		    <groupId>org.springframework.boot</groupId>
		    <artifactId>spring-boot-starter-tomcat</artifactId>
		    <version>2.3.0.RELEASE</version>
       </plugin>
    
    </plugins>

2.tomcat使用maven內(nèi)嵌入到web項(xiàng)目需要jdk運(yùn)行環(huán)境

eclipse默認(rèn)的運(yùn)行環(huán)境式j(luò)re,我們需要改成jdk

問(wèn)題解決:

3.springmvc依賴(lài)

Spring V4.1以后的版本運(yùn)行時(shí)會(huì)報(bào)如下錯(cuò)誤:

NoSuchMethodError: javax.servlet.http.HttpServletResponse.getStatus()

我們使用Spring V4.1以前的版本運(yùn)行,依賴(lài)如下

<dependency>
	    <groupId>org.springframework</groupId>
	    <artifactId>spring-webmvc</artifactId>
	    <version>4.0.1.RELEASE</version>
</dependency>

導(dǎo)入對(duì)象轉(zhuǎn)json的依賴(lài)

<dependency>
	    <groupId>com.fasterxml.jackson.core</groupId>
	    <artifactId>jackson-annotations</artifactId>
	    <version>2.9.5</version>
	</dependency>
	
	<dependency>
	    <groupId>com.fasterxml.jackson.core</groupId>
	    <artifactId>jackson-core</artifactId>
	    <version>2.9.5</version>
	</dependency>
	
	<dependency>
	    <groupId>com.fasterxml.jackson.core</groupId>
	    <artifactId>jackson-databind</artifactId>
	    <version>2.9.5</version>
	</dependency>

在pom.xml中配置jdk版本

   <properties>
	 	<maven.compiler.source>1.8</maven.compiler.source>
    	<maven.compiler.target>1.8</maven.compiler.target>
	</properties>

4.編寫(xiě)表現(xiàn)層代碼

@RestController
public class UserController {
	@RequestMapping("query")
	public Map<String, Object> query(){
		
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("code", 0);
		return map;
	}
		
}

5.配置web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>TomcatDemo</display-name>
  
                 <!-- 編碼級(jí)過(guò)濾器 -->
	<filter>
		<filter-name>characterEncodingFilter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
	</filter>
	
	<filter-mapping>
		<filter-name>characterEncodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
  
  <!-- 配置SpringMVC的核心控制器 -->
  <servlet>
  	<servlet-name>springmvc</servlet-name>
  	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  	<init-param>
  		<param-name>ContextConfigLocation</param-name>
  		<param-value>classpath:spring.xml</param-value>
  	</init-param>
  	<load-on-startup>1</load-on-startup>
  </servlet>
  
  <servlet-mapping>
  	<servlet-name>springmvc</servlet-name>
  	<url-pattern>/</url-pattern>
  </servlet-mapping>
  
</web-app>

6.SpringMVC的配置文件

<?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:mvc="http://www.springframework.org/schema/mvc"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" 
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans.xsd 
		http://www.springframework.org/schema/mvc 
		http://www.springframework.org/schema/mvc/spring-mvc.xsd 
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context.xsd 
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop.xsd 
		http://www.springframework.org/schema/tx 
		http://www.springframework.org/schema/tx/spring-tx.xsd">
		
	<!-- 掃描具有注解的類(lèi) -->
	<context:component-scan base-package="com.wn"></context:component-scan>
	<!-- 使SpringMVC的注解生效 -->
	<mvc:annotation-driven></mvc:annotation-driven>
	
	<!-- 配置靜態(tài)資源過(guò)濾器 -->
	<mvc:resources location="/" mapping="/**"></mvc:resources>
</beans>

7.配置完成后在項(xiàng)目上鼠標(biāo)右鍵

Run As->Maven build->輸入tomcat啟動(dòng)命令啟動(dòng)tomcat

tomcat:run

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

高安市| 开江县| 巴彦淖尔市| 乐亭县| 易门县| 皋兰县| 淮北市| 天全县| 天镇县| 武胜县| 洛宁县| 泾阳县| 卓资县| 庐江县| 漳浦县| 海口市| 攀枝花市| 平顺县| 吉木萨尔县| 信丰县| 景东| 晋中市| 鄂温| 息烽县| 铜陵市| 安顺市| 巴彦淖尔市| 景谷| 项城市| 泰顺县| 乌兰察布市| 洛浦县| 宜宾县| 仙居县| 井陉县| 牟定县| 淳安县| 滨州市| 洮南市| 湟源县| 蕲春县|