Should I use Spring AOP? [closed] - java

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I am new to Spring and I want to clarify something about it. I developed an application for student management, for private institutes. It can record student details (address, phone number, enrolled courses, grade etc...), course details, payments from students, report generating module, details about lectures etc.,
However, I didn't use much of AOP to develop this app, except for rare cases like logging. But Spring AOP is a big part in Spring according to my knowledge. My question is, is AOP a big part of spring or am I missing the places where I should have used it (I am guessing I made newbie mistake of not using AOP much)? If so, can you clarify me where I should have used these concepts, so that I can learn from my mistake.

My view is that AOP is great if you are building a framework (like spring), as it allows the framework to implement cross cutting code that doesn't greatly impact the users of the framework, for example in spring:
#Transactional
This one line of code in a service class invokes significant transaction management functionality.
However, for normal web-apps (for example), custom aspects should be used sparingly because:
they are less readable
an advanced technique, so not all developers will be familiar with them
tooling not fully supported (eg checkstyle, PMD, findBugs dont work with aspects), see: Code Analysis Tools and Inter-Type-Declarations

I think I've actively used AOP in only a handful of projects over the years. In my work with Spring I use it rarely compared to most of the other Spring features. As such, I'm aware of it and what it can do, but I don't worry that I'm not ticking that particular box.
It's useful to understand what it is, and what it can do for you. However Spring is doing work for you already that leverages this, and you're likely to be using it already without knowing it! Being aware of AOP and how it works is the major issue here. As such, it sounds like you have this covered.

AOP is a big part in Spring according to my knowledge
Yes it is,
As you are already using AOP for logging, for better understanding of AOP read here on aop
Basically aop increased you modularity of application by separation of cross-cutting concerns.
such as it helped you lot at the time of transaction management logging etc.
AOP in spring is used:
To provide declarative enterprise services such as declarative transaction management
To allow users to implement custom aspects.
source
For my understanding you can use transaction management in your application. as you are maintaing the records of students, course, fee etc associated with students.

Spring AOP used to tracking entire activity of user in large business applications. More like logging using AOP we can identify user consumed classes and methods and if any error occurs in any method, developers or customer helpers can identify problem soon and can give solution soon than reading log files.

Related

How to implement a servlet/applet combination with two different functions? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I've been tasked with creating a Java web application that consists of two pages, a "Draw" page and an "Evaluate" page. I'll be developing in Eclipse.
The "Draw" page will facilitate the following process:
Take user input from a form
Using a Servlet, build a model in the background
Send the model to an Applet (probably via JSON) on the client-side to be rendered visually
The "Evaluate" page will:
Take user input from a similar form to build a similar object (same class) using a Servlet
Run a the model through an algorithm on the Servlet, and display the results on screen.
The pages can be relatively independent.
My question is, exactly how should I go about implementing this combination?
I'm familiar with Servlet development and the Spring MVC/Webflow framework, but in no way an expert. However, I'm guessing Spring would be overkill for this simple application, and I've never implemented a Servlet that has more than one major function.
Should I make an HttpServlet that just has conditional logic in the doGet/doPost methods, and performs an operation based on the request's URL?
Should I make two separate Servlets?
If so, would I make two separate projects in Eclipse, or just one project with two Servlets registered in web.xml? Should I do something totally different?
I'm not looking for code, but just would like to have a stronger understanding of how to approach this type of application.
I'm going to provide an opposing view to that of Dmitri's. I think its great for people to know how to write plain servlets but when it comes to writing code for a business I think you'd be better off using Spring MCV. The main reasons are:
you already have experience with Spring MVC, so no learning curve
although the requirements seem straight forward, my experience is that web projects like this quickly grow way beyond their initial specs, at which point you'll be wishing you'd used Spring MVC
You will have to code and maintain the features in a servlet which are normally handled by Spring MVC - I love the saying: they have solved problems that you haven't even thought about yet.
every line of code you write has the potential to be buggy, by reducing the amount of code you write you reduce the risk of bugs
Spring MVC is designed in a such a way that you can use as little or as much of the features that you like/need. With annotations, you can get a simple app up and running with a surprising small number of lines of code/xml
testing is much easier with Spring MVC
Spring MVC follows a convention that other programmers already know. If you leave your job, then someone can pick it up very quickly. OTOH if you code a simple servlet, you could do it a number of different ways that could make it harder to maintain for someone else
with modern hardware/OS, the extra memory/overheads that adding Spring MVC adds to you project is negligible - we no longer run our servers with 128KB of memory but some people still have a mindset that we do. If in doubt benchmark it, don't early optimise!
Spring (or any other MVC) framework is definitely overkill for this, servlets will do just fine.
Make sure all of your actual logic is in a separate class, all your servlets should do is apply whatever processing needs to be done to read the user input, and call the appropriate methods on your service class. Basically keep the web-specific parts minimal.
Whether it's two separate servlets or one that switches on the request path doesn't really matter. I'd use two separate ones, since mapping requests to methods is pretty much what servlets are designed to do.
You do not need separate projects in Eclipse, just define the servlets in web.xml (or with annotations if on Servlet 3.0).
It sounds like you're on the right track.

What should I know before learning Spring? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Opinion-based Update the question so it can be answered with facts and citations by editing this post.
I've been learning Spring and I'm really liking what I'm learning, but feel ill-equipped to do anything at the moment. I know Java really well, I'm ok at ant, but I don't know anything about: J2EE, JSP, Servlets, Tomcat, Maven, Hibernate, JPA, and I've never made any kind of website using Java (I've made lots of applications in Java, but all websites I've made were using PHP).
Should I cement some of my knowledge of the "basics" or should I keep slogging away at Spring?
Spring is a monster. It all depends on what part of Spring you are interested in. A good starting point would be the Dependency Injection container, which requires none of the technologies that you are unfamiliar with (the ones from your question).
If you are interested in learning Spring MVC (which it sounds like you might be based on the technologies you mention), I would recommend learning the basics in these (again from your question):
Servlets
JSP
Tomcat (or another web application container)
For Spring MVC I would also look at the idea of RESTful web services.
You can find a (likely) comprehensive list of Spring projects at this link.
I would recommend three things:
Lots of Reading => Spring Documentation in a Single Page
Lots of Coding => You can start off by getting an example Spring / Hibernate project. And then use Spring Tool Suite, which includes many interactive tutorials, and template projects that just work without any coding at all.
Find a Spring User Group next to the place you live. If there is no such group => create one!
It is totally ok that you don't know JSP / Servlets / Tomcat / J(2)EE / etc. Extremely smart people who, for example, write Linux kernel (which is a lot more complex) may not know it as well. The beauty of Spring is that going through it, and reading about best patterns and approaches you'll get all the above. No need to learn J(2)EE separately. Spring is J(2)EE of today.
For a good enterprise developer, I would recommend
a) very very good core java ( including collections, jdbc , threads)
b) servlets
Then I think you can start diving into spring.
If you want to accomplish something quickly to start with, definitely look at JSPs. A JSP is basically an HTML document with some special <% %> tags where you can just shovel in java. It's really entertaining, although nothing you'd want to use for a large-scale application.

Which Java based workflow engine should I use? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I am looking for a off the shelf workflow engine to be used in my Java based web application. Following are my initial requirements -
The engine should have a nice UI to create/manage workflows.
Should work with Oracle database
Provides java api or web service api to interact with workflow from my application so that I can build logic on the workflow.
Ability to define custom business rules.
As of now I am looking at JBoss JBPM and Drools together. Do let me know if you have experience of this or other contenders which I should consider for evaluation?
You could try Activiti. I am personally experimenting on that. It's really easy to install and
use. It's similar to jBPM. So you would not have any difficulty if you are familiar to that.
You could also refer the comparison between them.
Hope this helps you.
yes i agree with you, jBPM is a flexible Business Process Management (BPM) Suite. It makes the bridge between business analysts and developer
and
drools is good and well manged rule engine , i recommend these both to use, but you will not have ready functionality like work with oracle database its individual functionality independent from this
I'd encourage you to check this list of Open Source Workflow Engines in Java
Scientific Workflows : Kepler, Taverna <--- these are both data intensive, and are easily distributable. They were designed to deal with genomics/planetary data, etc...
For business workflows, check out JBoss JBpm, which is transactional (i.e. its not optimized for massive computationally intense workflows, but rather, its written to support business workflows that need security, database transactions, etc.

JSF or MVC with Servlets/JSPs or other frontend frameworks? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'm working on development of a social web application using Java. I need to develop the frontend/GUI of my application for web browsers.
I'm wondering what is the better strategy to do frontend development, whether using frameworks like JSF 2.0 & like OR simply following MVC approach with servlets and JSPs ?
As I have heard JSF really makes the development simpler but also the learning curve is not too low, so is it worth learning JSF or I should prefer to directly proceed with servlets/JSPs ?
I'm new to web applications development using Java & I've almost completed writing the business logic for the application.
Please justify your answer on the basis of following parameters:
Performance & costs
Ease of Development & Time (considering the learning time as well)
Future Maintenance of code
Any other parameters you consider important
Update (07-09-2012):
I finally went with JSF-2.0 & have no regrets till date. Learning curve is not steep. It's easier & development is fast with component libraries like Primefaces. There are some costs as to state saving but those things can be handled intelligently. Community is big & things are well documented now. Hopefully, in near future Stateless JSF is also coming which will boost JSF with extra high performance.
For a hobby webapp, homebrewing some MVC framework is not bad. It's a nice learning exercise tour. However, it will bite you on the long term, for sure if you publish on the web and it becomes popular. Most of existing MVC frameworks are very well thought out. Most of the unforeseen caveats are taken into account. The sole framework API is well maintained and documented by a third party.
Also, whenever your webapp becomes popular and you need more developers to work on it to fulfill the enduser requirements/wishes, it's easier to find someone who's already familiar with an existing framework. With a homebrewed and possibly buggy MVC framework, you'll likely find less developers who are eager enough to dive into another learning curve before taking over the maintenance which they'll probably never reapply on their future jobs/projects.
This does not specifically apply on JSF, but on every other existing and popular MVC framework as well, such as Spring MVC. As to JSF in general, well, I've written a lot about it before here. Here are some good starting points to read the one and other about it:
JSF versus plain HTML/CSS/JS
JSF adoption and popularity
What are the disadvantages of JSF 2.0?
For modern web apps like yours, and if your responsibility is the UI, you really don't want any "abstraction layer" stand between you and your html/css/javascript. Don't use any "component" framework.
I have heard JSF really makes the development simpler
Did you hear that from real webapp developers who actually used JSF in real products? Or just JSF committee patting their own backs? Or some old timers' wishful thinking that they don't need to learn the darn javascript?
If you choose JSF, please report your experience back to us after you shoot yourself out of frustration.
It's better use some MVC framework.
You can use either component based framework:
JSF = mostly standard, but its hard to learn and a lot of people don't like itTapestry = quite big and probably good framework
Wicket, GWT - smaller component based frameworks, handy, powerful, smart, but I haven't used them yet
Or you can use request oriented framework.
Spring MVC, Struts 2 = They are very similar. Spring MVC have probably better documentation
Struts - I do NOT recommend this, when you can use Struts 2, or Spring MVC - you can trust me in this point
Each framework have its pro-and-con it depend on situation and your knowledge. I cannot give you single-valued answer.
Spring MVC is very easy to learn and if you have a simple web app and you want to save your time, its better than JSF.
However if your web app is not so simple, JSF beats Spring MVC by far. Its model is more complicated, but it is much better structured and it is widely supported, so that you don't have to reinvent the wheel again in most of the cases. Complex gui can done with JSF with less effort.
You might want to consider Tapestry 5 if you're exploring options. We've been happily using it for many years on a large project in the social media space. It's an easy to use MVC framework that's component based. We're able to develop rapidly with it, especially now that we've built up a lot of our building blocks.
Learning time is probably on par with ramping up on any new framework. I'd perhaps say it's less than JSF and more than Spring MVC, though it really depends on what you're already familiar with and how deeply you use things. I put together a very small project on github a while back to get started with Tapestry 5 quickly, if you're interested it's tapstack.
As for long term use of a Tapestry based application, it has served us well. Maintenance of the code has been much better than when were using JSP. It's very stable as well. We've served billions of page views through Tapestry without any major problems.
On the downside it is less common than some other web frameworks. It is definitely a little different too. We feel it's worth it though, and refreshing to work with. Ultimately it's going to depend on what you need and what you feel works best for you. Best of luck with your decision.

Is cayenne good choice for my requirement? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
We are evaluating ORM solutions for my project that has tight coupling between business layer and datalayer(JDBC). I started doing a PoC with Cayenne. My requirement goes like this
a) Already there exists database schema
b) Schema is very granular level. I.e. real time java objects are only derived by combining tables.
c) At the moment I just want to perform read operation (to be precise filter and sort on a list by inputing criteria)
Till now, the observations I have made with Cayenne are
1) Table and Object are tightly coupled. Modeler is not allowing to create java object without associated table.
2) I could not find easy way to map output of a named query to a java object so that I get list in a way application needs.
3) Also I am not sure Expressions work with named queries.
I would like to know your inputs on best choice for my requirement?
Thank you in advance.
If I had to choose an ORM tool or a JPA provider, it wouldn't be Cayenne simply because it doesn't seem to be widely used so the community behind it isn't very large and this is a concern. There is thus no need to discuss technical points, things like Cayenne 2.0 is intrusive, you have to implement an interface or to extend a superclass (Cayenne 3.0 has POJO support but is still in beta, after more than 2 years...). No, really, I don't see any good reason to not pick Hibernate, the defacto standard, if you need an ORM tool.
But...
Given your requirements, an ORM might actually not be the best choice, mosty because of b) so I would consider using iBatis (which is not an O/R mapper, it's a data mapper) instead.
Cayenne has a lot of very good features, and on the plus side you have a number of open source tools to use in your project. Hibernate suits some people and Cayenne others. I know that for more own use, Cayenne was far superior to Hibernate due mainly to these factors:
a very helpful user community. Hibernate's can be a little abrasive.
a very robust code base with a large number of tests which provide large code coverage
ROP (three tier) support. This in itself is a huge feature if you need it.
good inheritance support
Cayenne modeler
Yes, the Cayenne approach is that Object Entities (the Java clients which map to the db) extend a superclass. That gives you some distinct advantages over Hibernate (Cayenne controls the entire object lifecycle) and introduces complexities for some people.
I also find the way Cayenne manages the Context (a group of objects and changes which will later be committed together) to be very intuitive.
As for your questions:
1) Cayenne definitely lets you create Object Entities without a one-to-one map to a table. We do it all the time, particularly when modelling inheritance.
2) SQLTemplate will let you get at named queries, but you'll find that most ORMs will steer you away from this approach since you are working against the natural way an ORM works to build queries directly in the database. The point is to abstract the database whenever possible.
3) SQLTemplate will let you do just about anything you want. But again, adopting an ORM is about a strategy for writing your application, not just a light wrapper for JDBC. I believe the benefits are huge and our projects have benefitted, but it depends on your goals.
Agreed, Cayenne has a lot of very good features. But if your project need some work done with inheritance(you didn't mention it), definitively Cayenne is not a option. It doesn't do a "good inheritance support":
Horizontal inheritance - https://issues.apache.org/jira/browse/CAY-795 -open since 30/May/07;
discussion Vertical-inheritance on http://cayenne.195.n3.nabble.com/Vertical-inheritance-td827636.html since 18/May/2010
I often use it on my personal projects and the gain in productivity is excellent.

Categories

Resources