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>
pom.xml

修改 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>
web.xml

在 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>
applicationContext.xml

之后在将 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>
log4j.xml

到目前为止,基本的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

 

posted @ 2021-06-20 12:58  小祥工作室  阅读(520)  评论(0编辑  收藏  举报