Generate Spring Model Beans from XML beans configuration - java

Is there any way like eclipse plugin or something to generate Spring beans java classes automatically from a XML beans configuration file.
Or any similar kind of way. As I am doing a new project setup for REST API/ Spring/ Hibernate.
Thanks in advance.

Look at spring boot project starters. They can get you up and running quickly and there are many archetypes for common project requirements.

Related

How to write a framework on top of spring boot (i.e. write a spring boot application without implementing some interfaces)

I'd like to write a framework on top of spring boot that does a bunch of things, like exposing specific endpoints and doing specific logic.
But I'd like to build it as a framework in the sense that someone else can take it, implement a number of specific interfaces and it will then run as a spring boot web application.
I haven't found how to do this specifically.
I've looked into this article about writing a custom starter, but it looks like the dependency is the wrong way round. I want the custom code "plugged into" the framework rather than calling the classes of the starter directly, if that makes sense.
It seems you're looking for the EnableAutoConfiguration plugin. This is the core of any spring boot libraries that wants to deal with spring boot custom beans without user help. EnableAutoConfiguration classes need to be placed in spring.factories file.
spring.factories file can have multiple classes each class needs to be provided using org.springframework.boot.autoconfigure.EnableAutoConfiguration=A,B,C
Using these boot classes you can create many beans that could be the backbone of your framework. Also if you want to provide custom properties as boot does, you need to add those properties file spring-configuration-metadata.json file.
For your reference, you can see this repo Rqueue

How can I specify an external configuration file for a java application that is not spring boot

Background
I have built a console java application using kotlin and gradle.
The gradle file creates a fat jar which I can run from the command line using
java -jar <project>.jar
The jar contains the application.properties file from which properties are read.
Problem
I would like to specify on the command line that the application.properties file should be read from some external path.
When using spring boot, I have used
java -jar -Dspring.config.location=somepath/application.properties <project>.jar
and this works.
But it does not seem to be working in the non-spring boot application
Question
Is it possible to specify external configuration on the command line for non spring boot applications?
Spring boot has a whole chapter in the documentation which deals with various ways of configuration.
Obviously if you don't have spring boot you should implement something similar to it by yourself.
First thing you should decide - at which level you need the configuration to be integrated into your application:
Do you only want to read the key/values from command line or maybe rely on environment variables or system properties?
In general, what is the source of your configuration: Yaml? Properties file? maybe consul or etc.d?
Do you want to create a java object that reflects the configurations that you've read (like classes annotated with #ConfigurationProperties in spring boot do?
Do you want to support only one source of configuration or you want the various sources of configurations to be supported?
If you ware using Spring, do you want configuration properties to be automatically injected into beans?
If you're planning to use properties/yaml (like application.properties in spring boot) - where do you want to place them? Non spring boot application won't read them "auto-magically", you'll have to implement this logic.
Are you planning to deal with profiles (non-spring-boot application still supports flavors of loading different beans depending on specified profile).
Spring boot has answered all these questions and more.
Here are some options that you might want to give a try to if you're running outside the spring boot context but still have spring application:
Since spring 3.1, I guess, there is a#PropertySource annotation that you can use to make spring load properties from the file in the classpath or some "place" in the filesystem. This article summarizes the usage of this method as well as compares what spring boot has up on its sleeves as opposed to regular spring application. This is also a nice tutorial that covers regular spring features.
Something out of spring eco-system but still can be useful: apache common configuration project. There are some workarounds to integrate it with spring application, see here
Considering all the answers here I concluded that though it is possible to enable external configuration in applications that are not spring boot, it does require some effort.
Therefore I decided to use Spring Boot in the container.

Existing Java Web App and Spring STS (Spring 3)

Is it possible to take a project that I've been working on , import it into Spring STS and apply all the goodies that STS provides for easy Spring development to the project? For example, I'd like to be able to take this existing project which is not a Spring MVC application at the moment and treat it as though it was created as a Spring MVC template (kind of like wrapping the project in an STS MVC template). I hope this makes sense :)
As far as I am aware you can't decorate an existing project with Spring goodies just by importing it in to STS.
The best you can do is import and add the Spring project nature. This can be found by right-clicking on the project and selecting Spring Tools --> Add Spring Project nature.

Basic Spring 3 configuration for IOC

Can anybody tell me a basic configuration to use String dependency injection? What are the minimum required jars?
At the moment I'd like to use only Inversion Of Controll, maybe later I'll integrate ORM.
Thanks
Try Spring roo, there is nothing simpler than that to get a full fledged Spring based web application working, with all the dependencies wired together.
Spring STS (an Eclipse distribution customized for Spring available for free from SpringSource) contains several Spring project wizards that produce IoC enabled projects that you could use as examples.
Almost all Spring examples use Maven to define dependencies and download jars automatically from repositories available on the internet.

How to avoid Spring Roo GWT support?

I am experimenting with Spring Roo in a new GWT application. The Spring Roo GWT support is some way off ready for real use just yet, so I want to build the GWT stuff by hand using as much of the GWT 2.1 MVP stuff as possible. The problem I have is that Spring Roo "notices" my MVP-related classes and generates a whole lot of extra (broken) stuff for my entities.
How can I get Spring Roo to ignore the GWT side of my project?
"I want to build the GWT stuff by hand using as much of the GWT 2.1 MVP stuff as possible"
If you're building GWT by hand, it sounds like you're interested in using Spring Roo to generate your data model code — but don't want (or need) any of Spring Roo's web controller code. If that's the case then you can separate your project into two modules:
A module containing model and persistence code that is created by Spring Roo
A GWT web application that you create by hand.
Make the first (Roo) module a dependency of the second (GWT) module. Basically you're using Roo to create a JAR library that's used by your web application. As long as you don't run the controller command the Roo won't add any web application code to your module.
I renamed my gwt.scaffold package to gwt.shell and gwt.request to gwt.req and Spring Roo is leaving my stuff alone.

Categories

Resources