How to convert java to Spring XML bean - java

We have a java web project with initial configuration in Spring applicationContext.xml. Please don't write that it is old style, I know.
Part of this configurations can be change vs admin panel of the application and we need to backup it from time to time.
Does spring have something like applicationContext.saveBean() or any any other way to save configuration objects into XML using Spring beans?

You can use Spring caching with Ehcache:
https://github.com/eugenp/tutorials/tree/master/spring-all
You are getting the option of caching on disk stores.
You also can persist your beans as java serialized objects.
Of course this doesn't generate an xml readable output.

Related

what is recommended to store project configuration details in spring boot?

I'm a beginner with spring boot and java. My question is what is recommended to store Environment configuration details such as bigquery database name, aws service unqiue ids which are used in my project.
So, It is better to store in a class which is in core project or it is better to store in application.yml file
Because spring boot is so lightweight, a lot of projects use Spring boot for microservices. and in a microservice world, it's best and almost needed to store your configs in a centralized and secure place, so you can change any of them when you want.it's hard to save them in Java classes but you can easily save them with .yml or properties. in almost all cases .yml files will be better.
I think there are some options to save the information of the configurations in an application. One of them is use a *.yml to save all the information because you can have different configurations each of them per environment

Apache Camel XML configuration rules and restrictions

I am learning Camel and trying to integrate it with Spring Boot applications. From what I've read there appear to be two main ways to configure the Camel routes (and other related entities): 1) via Java DSL, or 2) via XML DSL. We don't think the Java DSL approach will work for us, as it doesn't seem that it would allow dynamic route definitions. Maybe I'm wrong? If dynamic routing can somehow be done using Java DSL and whatever, I'd like to know about it.
So, I'm focusing on configuring the routes in XML, where we should have a little more flexibility. The idea is that a given application (or service) could be handed a constructed XML route configuration at deploy-time that would specify the details of that service's routing.
The first question I have is how can we indicate to Camel (or Spring Boot and Camel) what/where the configuration file(s) are? Does it expect specific file naming and/or project location, or is it more flexible? Can it be broken into separate files?
By the way, we configure our Spring Boot applications via a combination of Java-based bean configuration and an application.yml file. We don't use XML for Spring Boot configuration.
I've poked around in a number of places on the Camel site (https://camel.apache.org/) but haven't found much information on this subject. The emphasis definitely favors the Java DSL approach.
There is a spring boot example with XML DSL at
https://github.com/apache/camel-spring-boot/tree/master/examples/camel-example-spring-boot-xml
You can use property placeholders in your Camel routes that can be configured via spring boot configuration (eg application.properties etc).
From Camel pov, then XML or Java can be equally dynamic. You can remove/add routes at runtime. But mind that its not always a good thing to do dynamic changes in production, without knowing if the changes works.

Best way of managing properties in Spring

I'm writing an application with Spring MVC which I'd like to be configurable with properties files. I looked into Spring's util namespace and found this:
<util:properties id="MyProperties" location="propertiesPath" />
with this, I can annotate my classes field simply with
#Value("myProperty")
and have the property simply injected. So, it's very simple to read your properties. But when you have to save them, it's not as intuitive.
I've stumbled upon quite a few questions on how to do it properly and I think this represents best what I want to say: Updating a properties file injected by Spring to include a last run timestamp.
My question is: why it's so difficult to save properties in Spring? Am I doing it the wrong way? At this point I am even wondering if saving properties this way is a good practice or if I should use a database.
From Oracle I can read:
The Properties class represents a persistent set of properties. The Properties can be saved to a stream or loaded from a stream.
But Spring seems to make easier only one of them. Please enlighten me.
Thank you.
Spring is largely involved in creating the static, unchanging, structure of your application, and not really involved in transaction processing or business-logic. Often it defines how transactions are to be processed, but it isn't usually involved in the processing itself. We often talk about the separation of the domain model and the architecture -- spring is about architecture.
Writing something out to a store of some kind, say properties to a disk file, is transactional logic (even if you don't need an explicit transaction to do it). It would be one of the end-user features of your system, not part of the architecture -- it would be a feature (even if the end user, in this case, is a sys-admin). Spring has little support for this type of behaviour -- just as it has little support for storing information regarding dynamic changes to the application context.
Using properties like this supposed it read-only. If you need some managing with it, you should better write you custom service with pure java properties handling http://www.mkyong.com/java/java-properties-file-examples/

GUI for management beans of Spring application

Good day everyone,
During my work I often have to run an overweight Spring application to generate some content. It took a lot of time just to load data in the memory and generate some predefined content. And if I need generate some other content I have to change some bean configuration and rerun all application starting with in memory loading.
I wonder is there a some GUI library/application that could help me run my application once and give me chance to manage and run my beans on the fly? Maybe some of you had experience of management Spring Beans via Java Swing that you could share with community?
Thanks.
If I was doing this from scratch I'd hold configuration in a Spring Cloud config server and then have beans with a scope of #RefreshScope.
As far as a GUI is concerned the config server stores the configuration in GIT so just use your favourite GIT client.
See the documentation here.

How many BeanFactories can a spring application can have?

How many BeanFactories can a spring application can have? I got this doubt when i see the source code of a spring based web application where they used an xml based configuration for a set of beans as well as annotation based configuration for the rest. Is this produce multiple bean factories or single at startup?
Definitely need more information on config to tell for sure.
The easiest way to find out is by using their visibility. Try to inject beans declared in the xml configuration in one of the beans using annotations, if it works they are using the same bean factory -
The probabilities are that it is the case. It is not unusual to have a mix of bean and annotation based configuration. Some people prefer to move configuration which they know for sure will not require to the flexibility of switching in a config file into beans. This reduces a lot of clutter in the xml configuration.

Categories

Resources