Architecture Spring MVC + angular app - java

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.

Related

Building Java Web-App with Vaadin in AWS

I have to write a (java) web-app, which fetches data from an AWS RDS Postgresql Instance, and renders the data using Vaadin Charts. So my two constraints are: (java) based, and using Vaadin to do so.
Thing is, I have never developped an form of web-app, and am complettely lost. I've read stuff about maven, spring, gradle , containers and am safe to say, have absolutely no clue where to start...
Could anyone point me to some complete tutorials about how to developp web aps from the ground up? everytime I google something I read something different and am completely overflown by information...
If you want to start with something working ASAP you can clone existing repos with vaadin examples. You will have existing code that builds, manages dependencies, starts webserver etc:
https://github.com/vaadin/dashboard-demo
https://github.com/vaadin/book-examples
https://github.com/vaadin/spreadsheet-demo
All the rest is probably opinion-based like should I you use maven or not? etc.

looking for Vaadin and Spring archetype

I'm starting to develop a new web app application with Vaadin and Spring, but I can't find an maven archetype for this.
Can you give me some assistance?
There is no such archetype. In fact, just to get those two frameworks working together at all, you're either going to need to go all wild-west and do it yourself (what I did) or use a plugin to get it working.
Here's the SpringVaadinIntegration plugin.. It takes an interesting approach to integrating Spring scopes with Vaadin sessions. The sample project for that plugin will be especially helpful for you to look at.
If you want to do it the do-it-yourself way, I can tell you that I divorced my vaadin from my spring as much as possible. Essentially I created some classes with static references to my spring singleton-scoped beans, and used those static methods for accessing my spring beans from Vaadin.

migrating a whole application from simple Java to Spring MVC

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.

Considering moving from Java/Spring MVC to Grails

I'm currently using Java & Spring (MVC) to create a webapp, and I'm considering moving to Grails. I'd appreciate feedback/insight on the following:
I have multiple application contexts in the current Java/Spring webapp that I load through the web.xml ContextLoaderListener; is it possible to have multiple application contexts in Grails? If, yes, how?
This webapp extensively uses a CXF restful web service and the current Java/Spring webapp uses the bundled CXF HTTP client. Can I continue to use the (Java) CXF HTTP Client in Grails?
I implemented Spring Security using a custom implementation of UserDetails and UserDetailsService, can I re-use these implementations in Grails "as is" or must I re-implement them?
There is an instance where I've relied on Spring's jdbc template (rather than the available ORM) and an additional data source I defined in app context, can I re-use this in Grails?
I plan on using Maven as the project management tool; are there any issues of using Maven with Grails where there is a combination of groovy and java?
Edit:
I'm considering moving to Grails to make the development of the web component of the webapp "faster," a la Ruby-on-Rails. Also, I'm considering Grails rather than say Ruby-on-Rails, because I want to continue to use the JVM and I've dabbled with Grails in the past and it was fairly easy to pick-up and use.
Probably. Grails uses a sub-class of Spring's ContextLoaderListener class which it configures in the web.xml file. I can answer more precisely if you let me know how you do it with Spring MVC.
Yes. You might even be interested in the CXF plugin, although I can't vouch for it:
http://grails.org/plugin/cxf
You should be able to use them as-is. However, you might want to check whether this is easily done with the Spring Security plugin. I believe it is, but you'll be able to get a definitive answer from Burt Beckwith, the author of the plugin.
Yes. You can also get hold of the Hibernate session factory to do raw Hibernate stuff. GORM can also work with multiple data sources:
http://grails.org/plugin/datasources
Another Burt Beckwith one :)
It depends on what you mean by "a combination of Groovy and Java". You can build Grails projects with Maven, but the integration isn't entirely smooth. If you have Java and Groovy in your Grails project, then that's taken care of automatically.
In response to Bozho, I use standard Grails services + GORM and wouldn't do it any other way. Note that if you use Java for services and the domain model, you won't have automatic reloading of services. You also lose the benefits of expressiveness and conciseness that Groovy bring.
If you want, you can use static types in Grails services to make it easier for your IDE to provide code completion. It can also give you hints on properties and methods it doesn't recognise (which would corresponding to Java compilation errors). That said, even if you use static types, Groovy can't do type checks at compilation time. You'll only find out about them at runtime.
You can do all these things in grails. It supports all existing Java classes and spring configurations (grails is built ontop of spring mvc)
However, I really wouldn't recommend moving the whole application to grails. You can perhaps move only the web layer, if you have web developers that are not java experts.
The service layer, the data access, etc, better remain pure Java. That is, only your web controllers - the components that gather the user input, handle http requests and sessions, should use grails. The rest - the stateless service classes and your domain model would better be Java. That's my opinion, but I have already some experience with grails, and static typing in the service layer will save you much trouble.
2) Yes you can use CXF as is. There is a nice layer on top of CXF called GroovyWS. I have only used it for consuming SOAP services, but maybe it has something for REST as well. It's really easy to use.
For consuming REST services I have used HTTP Builder
4) Yes. You can continue to use e.g. spring config for configuring the datasource, or any other way you do it today. Multiple datasources is no problem.
5) I have recently tried using Grails (1.2.1) with Maven. It works, but there has been some issues with both Maven and Grails trying to do dependency management. The documentation is maybe the worst part. I haven't tried upgrading to 1.3 yet because of some major Maven-related JIRAs, but 1.3.2 is right around the corner, and those issues have now been resolved :) There will also be a 1.3.2 maven archetype. Looking forward to that. "Deployment and resolution of plugins from Maven repositories" is one of the new features of Grails 1.3, so things are probably better. Roadmap for 1.3.2 says release today, but there are 8 issues left at time speaking, so my guess would be tomorrow, the Grails releases are usually on time. If you can wait for that, you will probably save yourself some trouble.
If you are looking for rapid application development but aren't otherwise particularly enthused about groovy, you should look into spring-roo. It offers the same kind of RAD functionality, but builds a completely standard java + ORM + spring-mvc app (which has no actual dependencies (runtime or compile) on roo). It's definitely not as mature as grails, but you may find that it better suits your existing experience with statically typed java code and existing ORM, etc. I've only done a couple of small pet projects in roo, but I've been very impressed so far, particularly with how easy it is to customize the generated code and move back and forth between written and generated code. The initial tutorial is very rapid and quite revealing.

Web Development In Java Using Netbeans

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.

Categories