简体   繁体   English

Java Web应用程序在哪里放置设置

[英]Java web app where to put settings

I have a multi-module Maven Java project in NetBeans . 我在NetBeans有一个多模块Maven Java项目。

Using Context env = (Context)new InitialContext().lookup("java:comp/env"); 使用Context env = (Context)new InitialContext().lookup("java:comp/env"); I can get settings from the web.xml file in the web app module code. 我可以从Web应用程序模块代码中的web.xml文件获取设置。

However, I can't work out how to get the settings in the other modules from the web.xml file. 但是,我不知道如何从web.xml文件中获取其他模块中的设置。

One of the other modules deals with email tasks such as sending welcome emails to new users. 其他模块之一处理电子邮件任务,例如向新用户发送欢迎电子邮件。

What I'd like to do is get the settings for the email server from the web.xml file into the email module. 我想做的是将电子邮件服务器的设置从web.xml文件放入电子邮件模块。 Currently, I have hard coded the settings in the code. 目前,我已经在代码中对设置进行了硬编码。

Then on the server the settings are easy to change if necessary. 然后在服务器上可以根据需要轻松更改设置。

Any help would be greatly appreciated. 任何帮助将不胜感激。

There are many ways how to do that. 有很多方法可以做到这一点。 You can put settings in properties files, or you can put them to pom.xml or into database. 您可以将设置放在属性文件中,也可以将它们放在pom.xml或数据库中。

It depends on when you want to change it. 这取决于您何时要更改它。 If you want to change it in compile time, choose pom.xml. 如果要在编译时进行更改,请选择pom.xml。 if you want to change it during stating up application, put them into properties files. 如果要在启动应用程序时进行更改,请将其放入属性文件。 And if you want to change them while app is up, save them into database (can be file). 而且,如果您想在应用程序启动时进行更改,请将其保存到数据库中(可以是文件)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM