idea建立普通Web專案lib目錄無法輸出,tomcat不報錯問題
idea版本:2021.2
tomcat版本:9.0.50
專案結構
建立一個普普通通的web專案,目錄結構大概就是這樣
.
├── .idea
│ ├── artifacts
│ ├── inspectionProfiles
│ ├── libraries
│ └── sonarlint
│ └── issuestore
├── conf
├── lib
├── out
│ ├── artifacts
│ │ └── test03_war_exploded
│ │ └── WEB-INF
│ │ ├── classes
│ │ │ └── top
│ │ │ └── ctong
│ │ │ └── controller
│ │ └── lib
│ └── production
│ └── test03
│ ├── generated
│ └── top
│ └── ctong
│ └── controller
├── src
│ └── top
│ └── ctong
│ └── controller
└── web
└── WEB-INF
lib
資料夾已經設定為Library
資料夾。
controller
搞了個hello
請求
@Controller
public class TestController implements Serializable {
private static final long serialVersionUID = 6290967590153117614L;
@RequestMapping("/hello")
public void test01() {
System.out.println("Hello World!");
}
}
配置了自動包掃描
<?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"
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">
<context:component-scan base-package="top.ctong"/>
</beans>
載入了DispatcherServlet
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
問題
點啟動,訪問/hello
成功榮獲404….幹掉out
目錄重啟….404…
重新建一個專案,啟動…..hello world
…..
再建立新專案,啟動…404
…
開啟FileMerge
檔案對比工具…嗯?差不多啊…
…開啟out
資料夾,嗯?怎麼lib目錄沒加進來…
…反反覆覆2天后…
…
…
…
解決
嘗試將lib
目錄拖進web/WEB-INF
目錄…hello world
…
不信邪,再把lib
拖到專案根目錄…404
…
……MMP……我之前一直這樣都沒問題…
不知道第幾次開啟 idea === >> Proiect Structure…
無意間點了 Proiect Settings ===>> Artifacts…嗯?怎麼有警告…..
Library lib ' required for module test03 is missing from the artifact
嗯?莫名其妙雙擊了右邊的lib
。警告消失了…
啟動…hello world
…
什麼妖魔鬼怪…