I posted following question for which I am still looking an answer.
Around Advice for methods on Interface
While looking in to this another question has come to my mind:
Are Point-Cuts and Advices only applicable to the classes which are declared as bean in spring's appContext.xml
Are Point-Cuts and Advices Is not applicable to all classes in the code-base ?
Straight from the Spring AOP documentation. THe documentation does say that Spring AOP is only for method execution join points(advising the execution of methods on Spring beans)
6.1.2. Spring AOP capabilities and goals
Spring AOP is implemented in pure Java. There is no need for a special
compilation process. Spring AOP does not need to control the class
loader hierarchy, and is thus suitable for use in a J2EE web container
or application server. Spring AOP currently supports only method
execution join points (advising the execution of methods on Spring
beans). Field interception is not implemented, although support for
field interception could be added without breaking the core Spring AOP
APIs. If you need to advise field access and update join points,
consider a language such as AspectJ. Spring AOP's approach to AOP
differs from that of most other AOP frameworks. The aim is not to
provide the most complete AOP implementation (although Spring AOP is
quite capable); it is rather to provide a close integration between
AOP implementation and Spring IoC to help solve common problems in
enterprise applications. Thus, for example, the Spring Framework's AOP
functionality is normally used in conjunction with the Spring IoC
container. Aspects are configured using normal bean definition syntax
(although this allows powerful "autoproxying" capabilities): this is a
crucial difference from other AOP implementations. There are some
things you cannot do easily or efficiently with Spring AOP, such as
advise very fine-grained objects (such as domain objects typically):
AspectJ is the best choice in such cases. However, our experience is
that Spring AOP provides an excellent solution to most problems in
J2EE applications that are amenable to AOP.
Related
I have seen a Spring application, and it uses spring dependency injection in addition to that some places I find Java Dependency injection. I am not sure why Java DI is used. I googled it, however, I can’t find an exact answer.
Anybody can explain why Java DI is used in addition to Spring DI?
Dependency Injection in Java is a way to achieve Inversion of control (IoC) in our application by moving objects binding from compile time to runtime. We can achieve IoC through Factory Pattern, Template Method Design Pattern, Strategy Pattern and Service Locator pattern too.
Spring Dependency Injection, Google Guice and Java EE CDI frameworks facilitate the process of dependency injection through use of Java Reflection API and java annotations. All we need is to annotate the field, constructor or setter method and configure them in configuration xml files or classes.
This link may help you more
To be simple, If you need Dependency Injection through Java you need to implement using some Design Patterns, which is time consuming. Frameworks like Spring helps to implement DI using annotations and configurations which are developed using specific design patterns. As a developer we need not worry about DI, we can just concentrate on our business logic.
I would like to use pointcuts of Aspects (Spring AOP) in Hadoop API. I don't want to modify the API, I just want to intercept the calls to the API methods. Is it possible with Spring AOP?
The bad news: No, it is not because Spring AOP is a proxy-based "AOP lite" framework which only works with Spring components. The syntax of Spring AOP is a subset of AspectJ, though.
The good news: If you use full AspectJ instead of Spring AOP, you can do what you want, because AspectJ is independent of Spring and can be used with any Java class (even with classes produced by other JVM languages such as Groovy or Scala).
I have an application in which beans are not initialized using the Spring BeanFactory/ApplicationContext.
There are few places where I find that Spring AOP can be useful and I want to apply these AOP features to the beans which are not part of a spring container.
So is it Possible to do so? And if yes, what can use to do the same?
we have a frontend application that that uses Swing. We use Spring framework, but currently it is used just to autowire few beans...
What are reasonable next steps to use Spring more often?
Is it worth for non web application?
What would be advantages and disadvantages?
The advantages of using Spring (or any other dependency-injection) framework, is that you get a (hopefully) loosely coupled system, i.e you classes does not create instances of their collaborators, so you can easily change the implementation.
This is widely known as the Inversion-of-control principle (IoC, also the I in SOLID), and this is a good principle to follow. This means that spring is not limited to web applications, but can be used in any application that want to use an IoC-container (which is basically what spring-core is).
Disadvantages:
This really depends on how you look at things. There is more code (you have to define a entry-point for the injected collaborators), but that also makes the code more testable (the entry-points are seams which you can use to inject mocks and stubs in testing).
Also, you can't look at the code and immediately see which implementation of the collaborators that are used. But that also makes for good code, since you depend on interfaces, not implementations.
You get more config: either in an xml-file (old-style spring), or with annotations. Up until recently you had to rely on non-standard spring annotations to inject (#Autowired) resources, but now you can use the standard java dependency injection annotations, which means that you can switch out spring as your IoC-container without changing your code.
There are probably alot more advantages and disadvantages to using spring in your application, but this should get you started on deciding if using Dependency Inversion is a good thing for your application
More to the point of your question about Swing and Spring. In an application I have been working on we have been using spring to wire up the whole application. The different dialogs get their logic injected (no application logic should (in my opinion) be located together with gui logic). We are using JPA/hibernate as the database-layer, so we use spring spring to create and inject the entitymanager to our DAOs, and set up transactional settings.
I've written swing UI's that are backed by spring.
cons
the startup can be slower but you have to have a large app for that to happen.
and a splashscreen is a good idea in those situations.
its easy to "overbean" or over-zealously make everything a bean, which gets messy.
pros
spring works fine behind a GUI.
it provides a lot of services you can use
the obvious dependency injection and decoupling
a global event system, simpifying some of your own event listeners, for events that will only ever be fired by one source
resource accessing
database access is eays in 2 tier apps
rpc for 3 tier apps is easy
There are other services the spring application context provides, but that I haven't used.
If you go this direction, also look into the java-based configuration for spring, which is new in 3.0. I find that helpful as well, as it makes my spring configuration type-safe.
One disadvantage of using Spring in a Swing application is that Spring DI will make startup slower.
well one would be , if you ever decide to migrate to a web app , all you need ( well almost) to change would be the views. That's the beauty of MVC applications.
i wonder how to create security annotation like spring security does (#PreAuthorized or #Secured) that will check session than do something to decide how application will threat the authority to log on user.
is any resource i can read or any recommendation?
best regards
ps: for some reason, i cannot use spring security
The technique behind these annotations is called Aspect Oriented Programming (AOP).
Spring Security relies on Spring AOP, which allows you to intercept particular method calls on Spring-managed object, so that you can apply security checks to them.
See Aspect Oriented Programming with Spring. Alternatively, if you want to do it without Spring, see standalone AOP implementations such as AspectJ.
The best tutorial for 'how does Spring Security work' is 'the source of Spring Security'. It is open source. You can read it. Honestly, the question as posed is much to broad to allow for much more of an answer.