Win a copy of Java Challengers this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Spring Framework - How to get Application Context when Spring Framework is started from Tomcat Serve

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am a beginner is Spring Framework.
1. Today I have a non Web Application which uses Spring Framework.
I have a class MainApp. Inside main of that class, I have following code segment:
ApplicationContext context =
new ClassPathXmlApplicationContext("Beans.xml");
TWDBJDBCTemplate twdbJDBCTemplate =
(TWDBJDBCTemplate)context.getBean("twdbJDBCTemplate");
INTFDBJDBCTemplate intfJDBCTemplate =
(INTFDBJDBCTemplate)context.getBean("intfdbJDBCTemplate");
Where beans.xml defines various beans for Sprig Framework ..

2. Now I am developing a webservice app using Eclipse Dynamic Web Project.. I do not use Spring Framework webservices at this point since that requires ne learning.
I have modified Apache Tomcat web.xml file to load beans.xml file:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/application-context.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
When I start tomcat I do see beans.xml file loaded…
3. My question is inside my web service app Java classes, I need to get
ApplicationContext context = ???
So I can use this context, to get beans defined in web.xml file, e.g.,
TWDBJDBCTemplate twdbJDBCTemplate =
(TWDBJDBCTemplate)context.getBean("twdbJDBCTemplate");
Appreciate if you can provide guidance how to do that. Thanks a lot,


 
Bartender
Posts: 1089
19
Mac OS X IntelliJ IDE Oracle Spring VI Editor Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May save you some pain if you look at using Spring Boot, in particular the Spring Boot Web starter project.
Start here - https://spring.io/guides/gs/spring-boot/

 
Getting married means "We're in love, so let's tell the police!" - and invite this tiny ad to the wedding:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic