I have one simple application running on simple Java code.
There is one server which takes data from client and just prints it back.
Now i want to move this application to Spring MVC so that my server will be running 24*7 and any client can be instantiated from web.
So what are the changes i will need to do ??
if required can explain in detail and also post code.
Start by getting the Spring Tool Suite and use that for your IDE. It's been a great help, since it comes with project templates, like MVC, that you can basically just plug your existing code into (assuming your code is already written in a way that can be used by other applications).
Once you have a basic MVC project, you can slowly add in your own code.
For more complete examples of Spring MVC form applications, the Spring Security project has a number of good samples. The important parts for you will be the methods inside the controllers that deal with form input, and you can ignore the security stuff for your application.
Related
I know and understand, And have read a lot about
Spring-Boot
, and how it's improving the use of Spring framework.
But I'm still not sure what's the actual meaning of
"Boot"
in the context of this title.
It's mean that it's kick off Spring to more high place, or it gives you boots to walk with Spring? Or something else.
Didn't found any explanation about that.
I will be glad for an answer.
(the source of the name
"Spring"
is also interesting )
Spring is a Framework of Java. Spring-Boot combined means Bootstrapping a Spring Application.
It simply means You have to configure your application to the bare minimum to get your Application up and Running.
Spring boot takes an 'Opinionated' view of what a basic Application should have.
Spring boot bootstraps your Application in such a way that it contains almost everything needed to run a full application.
Basically, Spring-Boot is a way to make a Spring Application up and running without a lot of configuration and boiler-plate code.
I have one maybe dummy, question but i really want to find better approach how build Spring app with angular. So essence of the question it's - should i put my front side to folders on java aplication, then deploy single app, or will be better if i create two differend app on java only REST and angular front?
It depends a lot on what are you trying to achieve with Angular and what parts of your front-end will be implemented using it.
I'd definitely suggest creating a separate module for every standalone independent feature you're implementing with Angular.
Spring has a few examples - https://github.com/spring-guides/tut-spring-security-and-angular-js. You could see the folder structure and the mechanism for unit testing.
Another good resource is https://dzone.com/articles/java-maven-angularjs-seed
jHipster https://jhipster.github.io/ is another good framework which sets up a maven or gradle project with the required project structure for angularjs and spring boot. They however use npm but its worth exploring.
I'm new to Spring.
The goal is to learn Spring, to use Spring as a production application as it is industry standard.
The requirements of the app:
Hibernate, Security, MVC, RESTful, DI, etc.
The other Spring frameworks might be added in future.
I'm reading "Spring in Action. Third Edition." by Craig Walls.
He gave the examples how to use annotations, but anyway .xml is used.
I'm wonder if I can write the application using only java classes to configure all modules in the application.
I found Spring Boot gives ability to develop not using xml files. However I read the article http://steveperkins.com/use-spring-boot-next-project/ and author said Boot is not ready to be used for production applications.
As far as I understood Boot hides all config work from me. Also my concern is that in future java-developers who knows Spring won't be able to deal with Spring Boot and I wouldn't find proper engineers for the project.
Based upon this I have the following questions:
Is it possible to avoid using xml in Spring or better to mix xml files and annotations?
Is it easy for Spring developers to work with Spring Boot?
Am I able to learn Spring using Spring Boot?
Is Spring Boot is mature enough to use it in production?
Is it possible to avoid using xml in Spring or better to mix xml files and annotations?
Yes, it is. Spring now promotes Java configuration, and it's perfectly doable (I'm doing it) and even easy to only use Java to configure your Spring app. Even without using Boot.
Is it east for Spring developers to work with Spring Boot?
Why wouldn't it? It's well documented, and is based on Spring best practices.
Am I able to learn Spring using Spring Boot?
How could I answer that. Try doing it, and you'll see if you're able or not.
Is Spring Boot is mature enough to use it in production?
Yes, it is. The articleyou linked to is one year old. Spring developers have worked a lot on Boot since then. And Spring uses Boot internally to host their own spring.io web application. See https://github.com/spring-io/sagan
JB Nizet answered 3 answers very clearly. Just an addition about production readiness from my side. We are currently using Spring Boot for an application which we intend to move to production. There has not been any issue till now in prototyping and testing phase. It is very convenient and avoids boilerplate and gives production ready, standalone jar file with embedded server. You can also chose to build war file if you prefer.
"Am I able to learn Spring using Spring Boot?"
As you mentioned that you are new to Spring, it would probably be easier for you to pick up Spring Boot quickly.
To get started, if you are interested, following is the link to a webinar by Josh Long which gives you a really good insight of how easy it is to pick up Spring Boot:
https://www.youtube.com/watch?v=eCos5VTtZoI
I don't know much about Spring Boot but I know pretty much about spring.
First of all you can use both annotations and xml configuration file/s in the same project. That is the most common way as far as I know.
There is also JavaConfig configuration option in which you don't use any xml files instead you use ordinary java class with #Configuration annotation. I didn't use and not saw much usage also.
You can make a spring webapp without any xml, although spring security was ugly to configure last time I looked at that. For a webapp you need to implement WebApplicationInitializer, create an application context and register your #Configuration file(s) with the context. Then you register the dispatcher servlet and you're all set!
I was nearly in the same boat four months ago when I started working on my web app & chose Spring as the platform after evaluating many choices. I also started with Spring in Action but got frustrated when the examples provided by the author didn't work (Spring basic MVC app not working). Since I was just starting, I was looking for some very basic but working examples. But unfortunately, most of the examples which came along with Spring text books, didn't work straight out of the box.
I would like to suggest few Spring resources which I found useful for starters:
http://springbyexample.org/
http://www.petrikainulainen.net/tutorials/
http://www.mkyong.com/tutorials/spring-tutorials/
Pro Spring 4th Edition
Spring Documentation (must read, but take your time to understand the concepts)
Now, to answer your questions, although a bit differently:
Is it possible to avoid using xml in Spring or better to mix xml files and annotations
Now a days, you would find Annotations a lot in Spring code available on net/SO along with XML configuration. However, you can certainly avoid XML if you wish.
Is it easy for Spring developers to work with Spring Boot?
Am I able to learn Spring using Spring Boot?
Is Spring Boot is mature enough to use it in production?
My personal opinion would be to go with Spring Boot only if you believe it offers you certain advantages which are not possible to achieve otherwise. Remember, you may save time now but later on, it would be an additional dependency in your app and you may need to understand its architecture to debug it if things go wrong OR to enhance it as per your app requirements. Better to have minimal dependencies, my learning till now :)
I am trying to implement a web application(university project) in java using the following Frameworks
Spring Dependency Injection
Spring AOP (Logging and Transaction Management)
Spring DAO
JDBC or HIBERNATE
Spring MVC
Log4J
I create a new Web Application in Netbeans and it gives me a bunch of Files and folders by default.
Could anyone explain me what are the files ?
Where shall i put the code for the data access layer and business Logic?
Or where can i found a basic tutorial to get started(with data access layer, business layer and possibly code example)?
Thanks
One area in which NetBeans is very good is the online documentation and tutorials so leverage them:
Introduction to the Spring Framework
Developing a Spring Framework MVC application step-by-step using NetBeans and GlassFish
Using Hibernate in a Web Application
etc etc
That is a ton of Java frameworks for a Web Dev course at a university. My advice would be to start small, because you don't need all of those libraries to get a working web application.
As you found, Netbeans is doing a lot of work for you that you really need to know to be effective. Do a simple JSP or Java Servlet tutorial to get something up and running quickly from scratch on a lightweight app server like Jetty or Tomcat.
Also, please take a look at what Model View Controller architecture is prior to diving into Hibernate or SpringMVC. This is a critical step!
It would be good to list the files that you got, but I think I can guess:
WEB-INF/classes is where your compiled .java code will go. Everything should be in packages, so the directory and package structures should match. Your Spring XML and Hibernate .hbm.xml configuration files will go here as well, because that directory is automatically in the CLASSPATH of your web context.
WEB-INF/lib is where your 3rd party .jar files go. All the Spring and Hibernate JARs, plus all their dependencies, belong here.
The WEB-INF/web.xml is where you'll map in the Spring front controller/dispatcher servlet, the context loader listener, etc.
I don't know what others you got. If you list others, I'll try to explain.
Here is Netbeans web application + hibernate tutorial.
http://netbeans.org/kb/docs/web/hibernate-webapp.html
code for business and data access would go under
your project name/Source Packages/
Thanks for your input, Drew.
I'm working on a Capstone project and we are thinking about using Netbeans for our Web-based project but were unsure about how difficult it would be to make the Web Based application in a relatively short amount of time. The application is for a College Testing Center and the application will track testing information and data for testing personnel and instructors at our college. I was going to try and follow a few tutorials here on the Netbeans site.
Thanks for your time.
PHP and HTML5 Learning Trail with Netbeans..
Here's a video as well.
Youtube Simple Web App instruction video.
Am a bit confused here! how does spring framework assist in general development of an application? I use django framework and i can quickly explain to a layman how all parts fit together(Django, Python, templates, packages etc) to produce an excellent web application, but when i look at spring i get a bit lost! Am looking answers but not limited to the following;
Can someone please tell me how they have used spring to produce applications?
Can someone please point to me some real world applications done in spring ( iread somewhere linkedin.com is done with spring!
Can someone please tell me how this pieces come together ( Strut, javascript, glassfish/jboss, apache, etc and ofcourse spring) to produce an application?
How many separate pieces of software do you need to produce an application using spring?
How easy is it to produce application using spring framework?
I need the gory details :)
Gath
There are a number of Spring projects, but the initial Spring (POJO) project came about because of the perceived difficulties of working with J2EE. You'll find a number of projects on the SpringSource website that have grown out of this, but rather than being lumped into one framework they've taken a more modular approach. For all the products they produce see:
http://www.springsource.org/projects
Q. Can someone please tell me how they have used spring to produce applications?
Spring provides a number of features, but the most oft used one is that of dependency injection. This allows you to wire together components (e.g. Javabeans) by declaring the relationships in XML/Annotations. The Spring container then reads this information and constructs the bean hierarchy at runtime. A standard way to describe the beans in XML is the Application Context.
http://static.springframework.org/spring/docs/2.0.x/reference/beans.html
Q. Can someone please point to me some real world applications done in spring ( iread somewhere linkedin.com is done with spring!
There are lots of applications built using Spring. I'm not sure of big commercial projects, but I expect there to be many.
Q. Can someone please tell me how this pieces come together ( Strut, javascript, glassfish/jboss, apache, etc and of course spring) to produce an application?
Spring is normally integrated with other frameworks, there are various hooks into these frameworks and you need to look at each one separately in order to understand what they are all about. Struts and Spring framework integration can be found here:
http://www.ibm.com/developerworks/web/library/j-sr2.html
With Glasshfish/JBoss it's more about how you configure your application in relation to Spring rather than the application server. See this:
http://static.springframework.org/spring/docs/2.5.x/reference/web-integration.html
Q. How many separate pieces of software do you need to produce an application using spring?
e.g. A web application would consist of Spring MVC + Spring Backend. A desktop application - Java Swing + Spring backend. In terms of the Spring framework itself (configured with XML) it would involve:
Create your standard JavaBean classes (for services/DTO's/DAO's)
public class ExampleBean {
private AnotherBean beanOne;
private YetAnotherBean beanTwo;
private int i;
public ExampleBean(
AnotherBean anotherBean, YetAnotherBean yetAnotherBean, int i) {
this.beanOne = anotherBean;
this.beanTwo = yetAnotherBean;
this.i = i;
}
}
Declaring beans within your application context file
Integrate Spring with your web application/application via web.xml etc...
These are taken from the Spring docs btw... see:
http://static.springframework.org/spring/docs/2.0.x/reference/beans.html
Q. How easy is it to produce application using spring framework?
Very easy, but again dependent on what you're building. If you're just using the Spring POJO framework to build a service and integration tier then it's fairly simple. If you have to build a web application layer, then it's a little more complicated (not hugely at all) to understand the internals.
Hope that helps...
Can someone please tell me how they have used spring to produce applications?
Put the Spring JARs in your CLASSPATH, follow the Spring idiom (e.g., interfaces to delineate layers), and use it to glue your code together.
Can someone please point to me some real world applications done in spring ( iread somewhere linkedin.com is done with spring!
Here's one. Running in production now for three years and counting.
Can someone please tell me how this pieces come together ( Strut, javascript, glassfish/jboss, apache, etc and ofcourse spring) to produce an application?
Struts is one choice for web tier; JavaScript is something you can use to make your client dynamic; Glassfish/JBOSS/WebLogic/WebSphere/Tomcat/Spring DM are all app server choices for deploying your Spring app; Apache is an HTTP web server; Spring and your code go on the app server.
How many separate pieces of software do you need to produce an application using spring?
You need an app server and probably a database, a browser, your code and Spring.
How easy is it to produce application using spring framework?
How good a programmer are you? Depends on your knowledge.
Spring certainly made my life easier once I understood it.
Spring is a pretty large framework, it's going to be hard for anyone to summarize everything here. I think the biggest plus for using Spring is its dependency-injection support. It can be used in any type of application, and provides a ton of framework features and utilities. If you are really interested, I'd recommend starting with the docs on springsource.org:
http://www.springsource.org/documentation
There are a lot of tutorials out on the web too. To fully appreciate it, you should try writing a few example apps to get the feel for it, and see what's available.
Just to add another dimension - if you are interested in building java web apps, and have no constraints (like legacy code to integrate with/update), then take a look at grails. its the best-est web framework to write web apps in. Of course, it uses spring internally too, but its fairly abstracted away from you. In fact, i'd liken it to django.
You can start with this http://static.springframework.org/docs/Spring-MVC-step-by-step/. This will provide the basic framework for you and then spring is huge so depending upon what you need you can explore spring and use it.
This has worked for me.
If you're talking about Struts and JavaScript at the same time, it means that you don't know what you're talking about, for Web Development in general.
What is what?
- You have frameworks in Java such as Spring, Struts, etc. which help you build Java based Web applications. Those Java Frameworks integrate generally Web with ORM tools, and other technologies.
- You have Servlet Containers such as Tomcat, Jetty, etc on which you can run classic Java Web Applications. J2EE containers such as JBoss, Glassfish embed a servlet Container such as Tomcat and provide a J2EE container and sometimes other tools, to deploy Java Enterprise applications.
Choosing a Framework
Choosing a Framework depends on how you feel about it and how it fits your needs. For example why are you using Django instead of TurboGears? Some people will tell you that Django sucks while TurboGears rocks, etc.
Whatever you do it's your call, read at the documentation and pick one application server and one or many frameworks to build your application.