java - Change Spring email settings based on dev/test/prod mode -


I often test my application with a copy of a live database, but not to do any work Be careful, it would be great to have a way of configuring spring to send an email to a user, when I am in Dev or Trial mode, no email will be sent to real users. Ideally, I would like all those emails which should go to the user rather than the mailbox I can check. And I do not want to change any code to do this, just XML config files.

I am already using Property Placeholder Configurator and I am reading in separate property files, if I am running in production, test, or dev mode Based on a JavaMailSenderImpl configurable. I am also using simple mail message to create a template from this address.

Ideally if I am running in Dev or in a test account, all the outgoing email addresses will be rewritten in the test mode.

My first thought was to use a separate SMTP server for Dev and Trial. But then I have to manage another mail server, and it needs to customize it so that it will not send mail anywhere but instead it will send it to a mailbox. It is possible that I do not want to add more management requirements.

Perhaps this is the best solution, but it seems that there should be a way to block email and change the recipient.

Has anyone been dealt with this problem before? What solutions have you come up with?

Note: My answer is based on using Maven, then it is

< P> jdbc.properties:

 

db.url = hostname: 1521 / test db.username = awful db.password = password < / Code>

applicationContext.xml (using context namespace)

  & lt; Reference: Asset-placeholder location = "Classpath: jdbc.properties" /> & Lt; Bean id = "yo" class = "some.data source" & gt; & Lt; Property name = "url" value = "$ {db.url}" /> & Lt; Property name = "user name" value = "$ {db.username}" /> & Lt; Property name = "password" value = "$ {db.password}" /> & Lt; / Bean & gt;  

Then I store domains in separate folders with specific values ​​such as:

  src / main / environment ++ prod +++++ Jdbc Properties ++ dev +++++ jdbc.properties ++ cert +++++ jdbc.properties  

Using a Maven Profile (from pom.xml):

  & lt; Profile & gt; & Lt; ID & gt; Environment & lt; / Id & gt; & Lt; Activation & gt; & Lt; Property & gt; & Lt; Name & gt; Environment & lt; / Name & gt; & Lt; / Property & gt; & Lt; / Activation & gt; & Lt; Construction & gt; & Lt; Resources & gt; & Lt; Resources & gt; & Lt; Directory & gt; Src / home / environment / $ {environment} & lt; / Directory & gt; & Lt; / Resources & gt; & Lt; / Resources & gt;  

You can run any maven command with -Denviroment property to flex the property:

  clean mvn -Denvironment = dev Testing MVN Clean -Network = CRT Package MVN Clean -Denaranty = Prada Deployment  

etc. And any file from that environment folder is copied to target or artifact with any source / main / resource files.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -