-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: dynamically set db password in Struts 2 +Spring +Hibernate
PostPosted: Wed Dec 22, 2010 3:21 am 
Beginner
Beginner

Joined: Mon Feb 02, 2009 3:22 am
Posts: 26
Hi all,

I have a web application of Struts2.2.1+spring2.5.6+hibernate3.3.1. The datasource is configured in applicationContext.xml like the following:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/db_ictboxm?useUnicode=true&amp;characterEncoding=utf8" />
<property name="username" value="root" />
<property name="password" value="passw0rd" />

</bean>


It works fine after the WAR is deployed, but in the case that the datasource parameters are different from that in applicationContext.xml, the hostname, the username and password, for example, I need to edit the applicationContext.xml to change these three values manually, and then restart the container tomcat, finally access the website.

Is there a way that allows the deployer to reset the three values, not by editing the applicationContext.xml?
can applicationContext.xml be read and saved by code? and do i must restart container tomcat after the applicationContext.xml is changed? how to solve this problem?

Lucy


Top
 Profile  
 
 Post subject: Re: dynamically set db password in Struts 2 +Spring +Hibernate
PostPosted: Wed Dec 22, 2010 6:18 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
the standard way to do this properly is to not use the datasource bean, but to have a datasource defined in the configuration of the application server (also Tomcat).
This configuration defines a JNDI name for the datasource, and you configure Hibernate to access this datasource.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: dynamically configure datasource in Struts 2 +Spring +Hibern
PostPosted: Sun Jan 23, 2011 12:15 am 
Beginner
Beginner

Joined: Mon Feb 02, 2009 3:22 am
Posts: 26
Hi ,

Your suggestion may partly solve the problem, but my reqiurement is to let the end user to configure the datasource by themselves. I created a Web application (Struts 2 +Spring +Hibernate), I want to let the user to download my application from my website and install it to their own machine. Once the user visit the homepage of the application, the homepage will check if the database can be accessed. If not , the user will be directed to a configure page. After the user input the url ,username and password of database properly, the application can run properly. This is my purpose.

Is there any way to solve this problem?

Thanks in advance.

Lucy


Top
 Profile  
 
 Post subject: Re: dynamically set db password in Struts 2 +Spring +Hibernate
PostPosted: Sun Jan 23, 2011 9:56 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
yes, in many creative ways, and no, this is not Hibernate's business :)
All code you provide to your customer is easily reverse engineered, so you'd need an asymmetric encription, but that's not supported by databases.
You could add a new user account on the database for each customer, or as people do more often keep hibernate on your remote webserver, and have people call via RMI / EJB3 remote into your application.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.