• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to display a dispatcher-servlet.xml bean id in a JSP page?

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm leaving this up in case anyone has any input, but I decided it was silly for me to try to do this this way. I just added an "environment" property to each of the beans, put the build.jsp page into the application proper as a view and set it within showForm() if the querystring contains a "build" parameter, and added the environment property to the model.


...

I have a Spring 2.5 MVC web application that can be deployed with any of several back-end environments. I have a bean for each environment defined in dispatcher-servlet.xml, and depending on the deployment environment, I edit my controller's bean in dispatcher-servlet.xml to reference the appropriate back-end environment bean.

I also have a JSP page accessible to the end user (not in web-inf, not mapped to a servlet), that gives build information. I would like the JSP page to also display the deployment environment information, since that is something that the user can't otherwise tell (the same front-end URL may use any of several different back-end environments).

Is there a way to include the environment bean name or bean id in the JSP page? That would be the id of the bean referenced by projreqController.dbSubmitter in the snippet below.

representative snippet of dispatcher-servlet.xml:


Thanks,

Rebeccah
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would upgrade your version of spring and use profiles. This is available in all Spring releases after Spring 3.1
http://blog.springsource.com/2011/02/11/spring-framework-3-1-m1-released/
http://blog.springsource.org/2011/02/14/spring-3-1-m1-introducing-profile/


If you still want to access the bean name you could implement BeanNameAware . This is considered bad practice for an application to have dependencies or to need to know these types of details. This is also mentioned in the java doc I linked. If you wanted to go this route anyway, when you implement this interface the framework will call the setter defined so you would have to define a bean name field and a getter for it so you could access it.


Previous to Spring adding support for profiles there were other workarounds people had used. If you google around you may be able to find some of them.
 
Rebeccah Quevedo-Prastein
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the off-topic reply, but what's with the spam link at the bottom of the page disguised as a post? I've seen jprofiler, jrebel, and probably others. The fake post reads, "I agree. Here's the link. <link to some software product or other> - it saves me about five hours per week."

Rebeccah
 
Rebeccah Quevedo-Prastein
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anyway, thank you for the links, Bill. As mentioned, I decided trying to get at the bean names was not a great idea, and I did find a different way to get the information that I wanted into the jsp page.

It looks like using profiles is a lot more complicated than simply editing two bean references in my XML configuration file, so I'll stick with what I've got there. I've really never understood why one wants to use annotations (except for automated testing) for most of what I configure in the XML file. I like having, and one of the originally touted benefits of Spring's dependency injection was having, the ability to get at some of this stuff (to see it and to modify it) outside of the compiled code.

Rebeccah
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No problem. Just as a note anything you can do with annotations can be done in XML including Bean profiles. One of the links I provided shows the XML way. Also unless you are not building your Spring configuration files inside your WAR it is unlikely somebody will ever crack open a deployed WAR to make changes to the XML, typically you would just rebuild it anyway. Anyways glad you got it figured out.
 
Rebeccah Quevedo-Prastein
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks again.

We deploy these (internal) applications typically to a server that expands the .war files on deployment, and we actually do tinker with the deployed files from time to time. Which is what led to the question. :-)
 
reply
    Bookmark Topic Watch Topic
  • New Topic