Basic Spring 3 configuration for IOC - java

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.

Related

How to configure DEV part in Spring Application?

I started Spring Project. I have added some dependencies.
Previously, I were commenting some dependencies as Security, Mysql driver, if it is not needed for me.
But how to disable them without commenting dependencies?
Maybe some properties are needed for that?
For example, I want to use H2Database to test project, but PostgreSQL I will use later. Or Spring Security, for example.
Do I have to use Spring Boot Profiles?
You are probably looking for profiles. You can read about it more eg: https://www.mkyong.com/spring/spring-profiles-example/
You may need to implement profiling for this. You can read about it more.
https://dzone.com/articles/spring-boot-profiles-1

Difference between spring modules and spring starter modules

What is the difference between spring modules (e.g. spring-boot, spring-web and etc) and spring starter modules (e.g. spring-boot-starter, spring-web-starter and etc)?
And which one should I use?
Spring Boot Starters were built to address the issue of dependency management. Dependency management can become very complex over time and you can spend a long time managing them in your project versus focusing on issues that really matter, like your business logic and bug fixes. Spring boot starters are a set of dependency descriptors that you include in your service.
Take the MongoDB starter for instance:
https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-starters/spring-boot-starter-data-mongodb/pom.xml
It has all the dependencies you need to connect to a MongoDB instance, all you need to do is add the starter to your service pom.xml and some configuration.
Spring modules, on the other hand, are part of the core spring runtime framework. They provide the fundamental parts of the framework such as IoC and Dependency Injection.

Generate Spring Model Beans from XML beans configuration

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.

Java Dependency Injection framework with Convention over Configuration feature

In this blog post Mark Seemann explains the different approaches to configure dependencies with a dependency injection framework. Convention over Configuration is one of this approaches. In the .NET world there are multiple DI frameworks which offers this feature (e.g. NInject, MEF 2). I'm searching for a DI framework with Convention over Configuration in the Java world. I looked at Spring and Guice but neither of them seems to offer this feature.
I would argue that hk2 has a convention over configuration like feature with automatic service population. It requires that you use the hk2-inhabitant-generator at build time to put some metadata into your built jar files. However, after that it becomes very simple to populate hk2 with your services. This is how GlassFish uses DI, where classloading at the start of the server had to be kept to a minimum in order to increase boot performance.
There's one for JavaFX by using afterburner.fx is JavaFX MVP framework based on Convention over Configuration and Dependency Injection.

Good project with spring-mvc and hibernate

Please advise me a project where I can see how to use Spring MVC and Hibernate together in the right way. I'm new to these frameworks.
Appfuse has a Maven archetype for this stack.
Strongly suggest you have a peak.
Alternatively the book Spring in Action was a great resource for me in learning spring and hibernate/spring interaction - use Annotation driven transaction management as well and you have a really great start.
see here: http://appfuse.org/display/APF/Using+Spring+MVC
appfuse-basic-spring is the basic project archetype.
Using maven modules is a better practice. ie)
appfuse-modular-spring
If you install m2e (maven 2 eclipse plugin) creating a new maven project will allow you to select the archetype.
better answer:
If I was going to recommend HOW to learn these technologies, I would say learn how to build a hibernate/maven/xml project first by following this:
http://www.mkyong.com/hibernate/quick-start-maven-hibernate-mysql-example/
Then learn how to use spring for dependency injection with maven/hibernate and xml:
http://www.mkyong.com/spring/maven-spring-hibernate-mysql-example/
Take special note of layering of the bo/dao pattern and how you use interfaces but wire in implementations with spring di - this is crucial for writing quality code
Next check hibernate annotations and annotation driven transactions:
http://www.springbyexample.org/examples/hibernate-transaction-annotation-config.html
http://www.springbyexample.org/examples/hibernate-transaction-annotation-config-code-example.html
http://www.mkyong.com/hibernate/maven-hibernate-annonation-mysql-example/
Finally, you can learn your mvc framework of choice. I actually recommend struts2 but it won't matter much. use spring DI by implementing interfaces and wiring implementations at runtime for you actions/controller. If you don't understand this how, you will after the hibernate/spring tutorials. Spring in action will be a good reference to keep on your desk but will take a few weeks to digest as you learn. Good luck! You can do it - I did and am now working as a java dev!
the petclinic app includes these, and many more things
spring-roo can create a skeleton project using these technologies for you.
If you are new to Spring MVC and Hibernate, I advice you to follow the Spring MVC step by step guide. The only problem with this is the version, the guide uses version 2.5 and the current release is 3.1.x, but it's a very good starting point to accumulate knowledge.
Spring MVC quickstart archetype provide simple spring-mvc and hibernate configuration.

Categories

Resources