欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
Spring and Jetty Integration

Spring and Jetty Integration

Jetty is a pretty darn awesome J2EE web container. With amazing features like non-blocking IO, continuations and immediate integration with Cometd - I feel that it is a solid, production ready container.

I hate war files, I hate web.xml files - there’s just way too much black magic that needs to be done to get things up and running. It is nice once someone has done the dirty work, and got the initial web.xml constructed, but I wouldn’t want to be that person who starts it all off.

Oh - another thing - I absolutely LOVE dependency injection. Using the web.xml approach, you’ll almost always have to start off a servlet of some sort to initialise various services that you’ll need - moreover the easiest way to access these services on other servlets is to use singletons, and we all know why singletons are bad!

So, I end up using Jetty in an embedded setup, and used to write various wrappers around the configuration so that I can do most of the common things with minimal code. A good example will be to setup a bunch of contexts and a DefaultServlet for regular file serving. However, the way Jetty is written makes it really easy to be used in Spring - everything is a simple bean with a bunch of setters.

To start off, lets write down the bean. Notice I’ve added an init-method attribute to start(). If you don’t want Spring to kick off your server, then just grab hold of the bean and call start() on it explicitly.

<bean name="WebServer" class="org.mortbay.jetty.Server" init-method="start"></bean>

Then, lets add some connectors to it:

<property name="connectors">  <list><bean name="LocalSocket" class="org.mortbay.jetty.nio.SelectChannelConnector"><property name="host" value="localhost"/><property name="port" value="8080"/></bean></list></property>

You will need some handlers (one of them will be a context handler to serve your servlets). I’ve added a logging handler so that the server logs requests in the same format as apache’s combined log.

<property name="handlers"><list><bean class="org.mortbay.jetty.servlet.Context"><property name="contextPath" value="/"/><property name="sessionHandler"><bean class="org.mortbay.jetty.servlet.SessionHandler"/></property><property name="resourceBase" value="/var/www"/><property name="servletHandler"><bean class="org.mortbay.jetty.servlet.ServletHandler"><property name="servlets"> <!-- servlet definition --><list><!-- default servlet --><bean class="org.mortbay.jetty.servlet.ServletHolder"><property name="name" value="DefaultServlet"/><property name="servlet"><bean class="org.mortbay.jetty.servlet.DefaultServlet"/></property><property name="initParameters"><map><entry key="resourceBase" value="/var/www"/></map></property></bean></list></property><property name="servletMappings"><list><!-- servlet mapping --><bean class="org.mortbay.jetty.servlet.ServletMapping"><property name="pathSpecs"><list><value>/</value></list></property><property name="servletName" value="DefaultServlet"/></bean></list></property></bean></property></bean><!-- log handler --><bean class="org.mortbay.jetty.handler.RequestLogHandler"><property name="requestLog"><bean class="org.mortbay.jetty.NCSARequestLog"><property name="append" value="true"/><property name="filename" value="/var/log/jetty/request.log.yyyy_mm_dd"/><property name="extended" value="true"/><property name="retainDays" value="999"/><property name="filenameDateFormat" value="yyyy-MM-dd"/></bean></property></bean></list></property>

And thats about it. If you need to add more servlets, then all you have to do is add an entry to ServletHandler’s properties for servlets and servletMappings.

Now, image if I had to get a reference to a DAO, or some other service in my servlet - it’s just going to be a matter of adding a member, exposing it via a setter and whacking in the dependency on the servlet Spring config above. All done in nice dependency injected way. No more overriding init() on the servlet and picking up some context attribute via some magic string. The best part of this

Here’s the whole Spring config - hack away to your needs!

<bean name="WebServer" class="org.mortbay.jetty.Server" init-method="start"><property name="connectors"><list><bean name="LocalSocket" class="org.mortbay.jetty.nio.SelectChannelConnector"><property name="host" value="localhost"/><property name="port" value="8080"/></bean></list></property><property name="handlers"><list><bean class="org.mortbay.jetty.servlet.Context"><property name="contextPath" value="/"/><property name="sessionHandler"><bean class="org.mortbay.jetty.servlet.SessionHandler"/></property><property name="resourceBase" value="/var/www"/><property name="servletHandler"><bean class="org.mortbay.jetty.servlet.ServletHandler"><property name="servlets"> <!-- servlet definition --><list><!-- default servlet --><bean class="org.mortbay.jetty.servlet.ServletHolder"><property name="name" value="DefaultServlet"/><property name="servlet"><bean class="org.mortbay.jetty.servlet.DefaultServlet"/></property><property name="initParameters"><map><entry key="resourceBase" value="/var/www"/></map></property></bean></list></property><property name="servletMappings"><list><!-- servlet mapping --><bean class="org.mortbay.jetty.servlet.ServletMapping"><property name="pathSpecs"><list><value>/</value></list></property><property name="servletName" value="DefaultServlet"/></bean></list></property></bean></property></bean><!-- log handler --><bean class="org.mortbay.jetty.handler.RequestLogHandler"><property name="requestLog"><bean class="org.mortbay.jetty.NCSARequestLog"><property name="append" value="true"/><property name="filename" value="/var/log/jetty/request.log.yyyy_mm_dd"/><property name="extended" value="true"/><property name="retainDays" value="999"/><property name="filenameDateFormat" value="yyyy-MM-dd"/></bean></property></bean></list></property></bean>
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
Jetty的配置
spring mvc中常見(jiàn)的幾個(gè)controller
jetty虛擬目錄
解析mediaTypes+viewResolvers+viewResolvers
spring and hibernate,spring and tapestry整合篇
十八、多視圖控制器
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久