![]() ![]() Maybe you don’t want to load your properties from a properties file, but from a database or web service! If you encapsulate your configuration in a service, that’s not a big deal. As any other service, you can easily change the implementation. If you do so, you will have a single point of responsibility to load and get your configuration from. ![]() ![]() You encapsulate persistence in DAOs, you encapsulate REST services in controllers and you encapsulate security in authenticators. Instead of this, configuration should be an encapsulated service of your application such as any other functionality, too. You will have a lot of fun if you want to rename one of those keys or when you need to set each and every property for each and every class in your unit tests. You will end-up with doing a full text search on your project to find out where a single key is used. You will have no idea or control which class is using which properties. Every class can pick a couple of properties to use. However, this means nothing else than scattering your configuration about your whole application. That’s easy and absolutely what the mechanism is about. You will inject it in services, controllers and components and you will properly inject the same property in different classes. What will happen when you use this technique through your application? Well, whenever you need some property, you will inject it. If you do so, Spring would inject the value for the key my. from your properties file right into your class and you are done. ![]()
0 Comments
Leave a Reply. |