You are now in the test environment. Your actions here will not affect the system.
Send an e-mail to: ${environment.get('email')}
~~~
## Accessing configuration files according to the environment
If you need to access a file in a different setting for your libraries according to your environment, you can also use the environemnt. Just put, for example, your `hibernate.cfg.xml` under directories located with the name of your environment: *development* and *production* (for example). `Environment.getResource (...)` returns the resource according to your current environment:
~~~
#!java
cfg = new AnnotationConfiguration();
cfg.configure(environment.getResource("/hibernate.cfg.xml"));
~~~
To keep compatibility with applications that don't not environment, if the file isn't found in the directory with the name of the environment, it will be loaded from classpath.
## Injecting the value of your configuration programmatically
You can also inject your settings programmatically using `@Property` annotation, like:
~~~
#!java
@Controller
public class MyController {
@Inject
@Property("email")
private String email;
public void sendMail(String email) {
sender.sendMailTo(email);
}
}
~~~
If your environment is `DEVELOPMENT`, the value for key `email` will be loaded using `development.properties`. And if your environment is `PRODUCTION` the value will be loaded from `production.properties`. This feature allow you to keep away from conditional statements like: `if (environment.isDevelopment ()) {...}` in your code.
And if the field name is the same from the key, you can use only the `@Property` annotation without define a value, like this:
~~~
#!java
@Controller
public class MyController {
@Inject
@Property
private String email;
public void sendMail(String email) {
sender.sendMailTo(email);
}
}
~~~
You can also set a default value for this property:
~~~
#!java
@Inject
@Property(defaultValue = "config.properties")
private String fileName;
~~~