Rose + Resin 在idea 可以跑起來的入門案例
一、前提
1. 這篇文章在說什么
下文主要介紹如何在idea 中部署一個 Rose框架的Java web項目,且以 Resin(web 容器)在本地debug。
如果你在找非此類文章,可以跳走了。
2. 框架和Web服務器說明
Rose:它是一個Java Web框架,和Spring MVC 有些類似。(如果我說了算,我肯定不用這個框架??)
Resin:一個實現了Servlet API的的web容器。好處可以度娘。(但我個人認為在Tomcat、Jetty以及微服務的環境下實在不了解他的優勢)
3. 開始搭建
用maven的quick starter建立一個web項目(就是為了快速,也可以自己建立)

之后引入pom中的各種依賴
<dependencies> <!--paoding rose需要的一些jar包 --> <dependency> <groupId>net.paoding</groupId> <artifactId>paoding-rose-jade</artifactId> <version>2.0.u01</version> </dependency> <dependency> <groupId>net.paoding</groupId> <artifactId>paoding-rose-web</artifactId> <version>2.0.u01</version> </dependency> <!-- log4j --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> </dependencies>
修改 web.xml。目的是配置rose
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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>Rose-Example</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> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>/WEB-INF/log4j.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <context-param> <param-name>portalExecutorCorePoolSize</param-name> <param-value>5</param-value> </context-param> <filter> <filter-name>roseFilter</filter-name> <filter-class>net.paoding.rose.RoseFilter</filter-class> </filter> <filter-mapping> <filter-name>roseFilter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> </filter-mapping> </web-app>
在 resoures目錄下新建applicationContext.xml. 開啟SpringIoc.這里注意 spring-context的版本。paoding-rose里面會有spring-context的引用,結合當前的版本
<?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:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd" default-lazy-init="true"> <!-- 自動掃描 --> <context:annotation-config /> <context:component-scan base-package="com.wx"> </context:component-scan> </beans>
之后在將 WEB-INF的log4j文件填寫一下
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="stdout" class="org.apache.log4j.ConsoleAppender"> <param name="Target" value="System.out" /> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="[%-5p %d{yyyy-MM-dd HH:mm:ss.SSS}] %l (%m)%n" /> </layout> </appender> <root> <level value="error" /> <appender-ref ref="stdout" /> </root> </log4j:configuration>
到目前為止,基本的xml配置差不多了。
在base-package下建立自己的package。比如我通常會用 com.wx,然后在該包下在建立 controllers。注意這里帶一個 ‘s’

開始配置resin。
首次使用需要在plugin中找到 resin插件。安裝

然后去下載。resin-4.0.65.tar.gz(mac linux)解壓
開始在idea中配置resin

將紅色框中的按圖配置,綠色有的人可能沒有就不用關了,有的刷說明artifacts 沒有,file-》project structure-> Artifacts看下。正常這里應該是有的,沒有自己加一下
如果有綠框錯誤,在上圖中的頁面點擊 Deployment 在Deploy at the server startup 種添加Artifacts

點擊Debug啟動。
http://localhost:8081/hello/world

寫在最后。
我的環境是jdk 15.可能是這個rose包太老了。報錯:
probably due to a new Java class file version that isn't supported yet
解決方法:idea -> preferences -> build,Execution, Deployment -> Compiler -> java Compiler 將其設置為jdk 7


浙公網安備 33010602011771號