I have several properties related to the configuration of my app that I'd like place into a single file, in order to centralize configuration. The source for this app will be used and modified by others, so I'm trying to make it as simple as possible by providing a single configuration point.
I'm aware of how to use MyComponentName.properties files for customizing component error messages, L10N etc. But I'm trying to provide configuration for things that aren't typically display strings. Some examples:
My Application.java would load these properties from global.properties (or whatever) and hand off the appropriate configurations to my individual classes at init time. I can certainly load the file manually, but I'm wondering if there isn't already some kind of support for this in Wicket.
Would it be better to place these into the web.xml?
I have used two approaches.
First Approach, using web.xml with the wicket application init parameters:
<filter>
<filter-name>WicketApp</filter-name>
<filter-class>
org.apache.wicket.protocol.http.WicketFilter
</filter-class>
<init-param>
<param-name>applicationFactoryClassName</param-name>
<param-value>
org.apache.wicket.spring.SpringWebApplicationFactory
</param-value>
</init-param>
<init-param>
<param-name>param1</param-name>
<param-value>xxx.xxx.xxx.xxx</param-value>
</init-param>
<init-param>
<param-name>param2</param-name>
<param-value>Hello</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>WicketApp</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
You can access them using:
MyApplication.get().getInitParameter("param1")
Second approach, if you use Spring, you can use your applicationContext.xml to parametrize your beans:
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="mail.xxx.com"/>
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.sendpartial">true</prop>
</props>
</property>
</bean>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With