Swing application with Hibernate and Spring - java

Can we use Spring as Controller and Hibernate as ORM tool for an application with User Interface SWING??
If yes how??
How will be its directory would appear. How all injections will takes place. For simplicity maintaining a environment for saving Text fields input into DATABASE using Hibernate.

Spring could not be used as Controller in desktop application (Spring MVC is a web framework), but it can be used for features such as autowiring.
However Spring and Swing does not play well together, my last attempt failed due to really inconvinient configuration and lots of overhead code.
Some time ago there was a project called Spring Rich Client, but seems to be abandoned.
Anyway - internet is full of examples of using Swing with Spring, but you have to know that this pair is "not that popular".
Spring: How to Create Decoupled Swing Components
SPRING HAND IN HAND WITH SWING APPLICATION FRAMEWORK
Using pair of Hibernate and Spring is not different than in web-application case.

No. You cannot use Spring as a controller. But you can use core Spring container for using in Dao and Service layer. Hibernate for using Object mapping with Database Table.

Related

Spring features and significance?

Spring empowers POJO based programming.
It offers support for MVC out of the box
wires up code in less time.
How does it support layered architecture?
provides an abstraction layer to simplify development process(why is this a benefit and how does spring handle this?)
How does spring do that?
I read a lot of articles talking about the advantages of spring. But none of them explain in theory i.e. in words not code, how spring does that?
for example, one of the advantages says it empowers POJO programming? we can do that with plain java too, why is that a benefit or what's the opposite of POJO?
Kindly request everyone to address those 3 questions. THanks
in short:
spring was created a long time ago. it was probably compared to ejb2 that needed more setup code. POJO vs EJB vs EJB 3 Also spring does support pojos for example as return value in MVC-controllers. pojos dont have external dependencies so your application stays portable (non-functional requirement of an application).
yes you can easily (my opinion) create web applications.
at its core spring provides a container in which bean definitions are stored. when a service is requested that needs a dependecy, spring can look up whether it has a bean definition for that dependency, construct an instance of that bean and inject it in that service. That way you dont need to manually instantiate your service.
for example in web applications spring has abstractions for controllers, services and repositories. typically an application provides controllers so that caller can use your api. controllers should call services that handle your business logic. and services can call repositories that persist your data. that way you have a layered flow:
controllers --> services --> repository
this has the advantage that when you change e.g. your repository you dont have to make changes to your controllers.
spring provides many abstractions for common problems out-of-the-box (e.g. spring security) and empowers convention-over-configuration. That way you can reduce boilerplate code. less code -> less probability for a developer to make a mistake.
e.g. spring-security-oauth2: you can just set some properties in a .properties file and spring autoconfigures beans that solve the validation of an oauth-token when a user requests one of your controllers.

Spring web-based admin tool with CRUD

In PHP & Symfony world there is a tool called Sonata Admin https://sonata-project.org/ based on AdminLTE template, that is all-in-one admin tool with login, menu configuration, and what is most important - database tables HTML grid CRUD generators.
The tool saves you tons of efforts by avoiding you writing boilerplate code, moreover, there might be a scenario that you would write zero code.
We need the same but for Java and Spring stack. Any recommendations?
Take a look at JHipster project https://www.jhipster.tech/
With it you can create Spring Boot+Angular/React/Vue based applications. It provides some cool tools for generating CRUD entities by scaffolding.
https://www.javatpoint.com/spring-mvc-crud-example contains an example of how to create a Spring MVC CRUD there are plenty more examples of various spring project (This particular falls under Spring MVC).
This is not a ready-made CRUD, but a way how you could quickly implement one.
https://spring.io/guides/gs/crud-with-vaadin/ is also worth checking.
Although there are few project like spring batch admin (For batch administration), or Spring boot admin (Monitoring spring boot applications), which provides a UI, mainly spring project provides a simple programmatically way of plugging in what's needed.
It's a plug & play kind of framework which targets various aspects of an enterprise application. Chances of finding a ready-made UI app would be more on GitHub rather than a specific spring plugin.
Simple answer to your question is No spring does not provide any tool for that but spring gives you the functionalities that can reduce your work but not with zero coding.
example:
Using Spring Data JPA there is an Interface name curdRepository which
takes care of the curd Operations we dont need to implement the methods
for Curd Spring takes care of Curd operation.
Spring Security Provides the login configuration with the login form and logout mechanism.
You can use spring boot or just visit the https://start.spring.io/ it will initialize the spring project with the dependencies you need

Is spring MVC purposed for web pages?

I want to build a server for my android application.
My application lets users register and allows each user to request a list of all users registered to my application, so my server will be mainly in charge of receiving data from a user, updating the database, and sending data back to user on request.
Since I've never built a server I looked into what would be the ideal way to achieve my goals and after some reading I've found that Spring would be the right way to go, But I also found that there are all kinds of springs.
Eventually I've narrowed my options down to Spring MVC and spring Boot,
I've read that spring boot is a good start but I also read that spring boot does all the configurations for you and I want to really know how stuff works so I fear that spring boot will do all the work for me , So I thought of maybe using spring MVC but I couldn't completely figure out if Spring MVC would be good to achieve my goals or if it's mainly used for building web pages
So what would be the best suitable spring to use ?
I would prefer Spring boot. It's not just about it doing all the configuration for you. It's about Spring saving you from writing a lot of boilerplate code (you still have to do a fair bit of configuration though). Plus, it will be easy to spin up the app and test it locally (you can even test it with local file based h2 database, meaning you don't need to install any database into your machine).
Adding Spring Data JPA dependency with Spring boot will take care of persistent layer as well. And if you want to write jsp or html pages then I would recommend having a look at this thymeleaf example.
Here's the sample CRUD application I have developed with Spring boot and here's my own blog about it.
Spring MVC stands for model,view,controller. View, in general is something which is returned after your business logic has been executed and mainly suggests webpages. Spring Boot would be the easiest way to set up your server for the application. However, if you want to know how things work you can go with the basic spring. Spring, too provided classes like JdbcTemplate to reduce your boilerplate code, however it forces you to configure things yourself.
You do not have the comfort of annotating a resource and watching as the magic happens. If you want to speed up setting up a server and make things less complex go for Spring Boot.

Designing and implementing mobile web application

I would like to design and implement a mobile web application using JQuery mobile and Java EE technology.
The application will consists of sales persons using the mobile device to take an order when they visit the customers. So the application will contain complex business logic.
I am confused as to with what frameworks I should pick/select to design and implement the server side of the application. So my question is should I use Spring, Spring MVC and Hibernate together or some other suggestion?
But I want to stick to Java technology as I am comfortable with it.
My next question is how will the JQuery mobile and the server side integrate with each other. I mean what are the ways/methods to integrate them?
Your best bet would be to avoid Spring in this case.
Use straight Java EE, with JAX-RS, CDI/EJB and JPA.
Your jQuery code will call JAX-RS resources (which are ReSTfull web services). Those resources are injected with Service beans, which are a combination of CDI and EJB. These beans will contain your super complex business logic. If they need to retrieve or store something from/into the DB, they will use JPA for this via an injected entity manager.

How to reenginering web application from Spring MVC to JSF?

What can I use for data access, timers etc? Seam, jBoss, GlassFish? Or simply Tomcat + JSF + Hibernate/JPA?
I need add just one JSF component to Spring MVC pages but I am afraid I must rewrite whole web app to jsf and drop Spring.
jbo, If you are just interested in replacing your view layer, you need not switch to hibernate/jpa etc.. JSF can co-exist with spring MVC. Need not discard any of you business objects and DAO's.
Better option is to consider spring-webflow. It is built on spring-mvc. Also support jsf views
http://www.javaworld.com/javaworld/jw-11-2008/jw-11-intro-to-swf2.html
http://www.springsource.org/webflow
http://www.springsource.org/webflow-samples
I see here an example about using jsf with Spring.
Also take a look here.
Maybe it's useful for you.

Categories