日期:2014-05-16  浏览次数:20803 次

当使用spring mvc 的restful架构后,apache+resin的配置问题

?

下面长话短说

技术架构:

Spring MVC(RESTFul)+Spring+JPA(Hibernate)

应用软件

Apache+Resin+Window/Linux+MySQL/SqlServer/Oracle/DB2

?

传统的apache+resin配置(官方教程),apache能够处理静态内容,resin处理jsp、servlet内容

但由于使用RESTFul架构后,大部分的Controller访问地址都无后续名,导致resin不去解析,传统配置无效

(PS:Tomcat 的AJP模块支持排除响应方式,因此无这个问题)

因此,这对这种环境和需求,可以参考下面的配置,通过反向代理形式实现:

?

?

#resin配置

#LoadModule caucho_module C:/resin3.1/win32/apache-2.2/mod_caucho.dll

#ResinConfigServer localhost 6800

#CauchoConfigCacheDirectory /tmp

#CauchoStatus yes

?

#<Location /caucho-status>

? #SetHandler caucho-status

#</Location>

?

#

#由于apache+resin的旧配置,无法处理restfull的应用

#因此,当需要使用apache+resin,同时也要全网支持restfull,暂时只能使用反响代理模式

#

?

?

<VirtualHost *:80>

? ? ServerAdmin webmaster@dummy-host2.localhost

? ? DocumentRoot "C:/www/cms"

? ? ServerName localhost

? ? ErrorLog "logs/dummy-host2.localhost-error.log"

? ? CustomLog "logs/dummy-host2.localhost-access.log" common

?

? ? ProxyPreserveHost On

?

? ? ProxyPassMatch ^(/.*\.htm)$ !

? ? ProxyPassMatch ^(/.*\.html)$ !

? ? ProxyPassMatch ^(/.*\.shtml)$ !

? ? ProxyPassMatch ^(/.*\.css)$ !

? ? ProxyPassMatch ^(/.*\.js)$ !

? ? ProxyPassMatch ^(/.*\.gif)$ !

? ? ProxyPassMatch ^(/.*\.jpg)$ !

? ? ProxyPassMatch ^(/.*\.jpeg)$ !

? ? ProxyPassMatch ^(/.*\.png)$ !

?

? ? ProxyPass / ?http://localhost:8080/?

? ? ProxyPassReverse / http://localhost:8080/

?

? ? #<Proxy *>

#Order Deny,Allow

#Allow from all

? ? #</Proxy>

?

? ? <Directory "C:/www/cms">

Options Indexes MultiViews

AllowOverride None

Order allow,deny

Allow from all

? ? </Directory>

</VirtualHost>

?

?

但用过apache反向代理的人都知道,它也会带来其它问题,如ip获取、路径获取、域名等。

这些都需要开发人员去对应。