java - How to make legacy HttpServlet Spring web aware -


we have legacy httpservlet class backbone of our application. @ point, app doesn't have spring libraries in it. looking introduce spring, in particular can use spring-data in conjunction hibernate.

i wondering if there way make legacy servlet web-aware can have request , session scopes injected. in particular, able inject httpservletrequest object beans.

one of main reasons need this, weird multi-tenancy solution have in place. hibernate can handle multi-tenancy using combination of abstractmultitenantconnectionprovider , currenttenantidentifierresolver when using spring-jpa's repositories, lose control of session creation. 1 way take care of implement currenttenantidentifierresolver since our tenant identifier partially determined comes in on request, necessary inject request our currenttenantidentifierresolver implementation.

also, great spring involved other benefits can provide in legacy app.

do know how can accomplish this?

you can define org.springframework.web.context.contextloaderlistener within web.xml, load spring application context.

then, within servlet code, access context using webapplicationcontextutils.getwebapplicationcontext(servletcontext) helper method.

take @ spring docs here: http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#web-integration-common


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -