• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

@Around annotation / <aop:around> Configaration in XML file, showing unexpected Output

 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I posted all my code below.

spring.xml


LoggingAspect.java


Triangle.java


Circle.java


Sahpe.java


AopTester.java


Output is:


Its perfect. But, In AOPTester.java if you replace LINE 1 as

It's giving NullPointerException. I thought output would be


Can anyone Explain me, what's happening(cause for exception) when I call ?


Second Doubt:
When I print that, like


It's showing "null". why?
Thanks:
Ramakrishna k.c
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have not initialized the circle member inside your shape. So, shape.getCircle returns null. When you try to call getName on shape.getCircle, you get a NPE.

You should inject the circle into the shape.
 
Ramakrishna Udupa
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jayesh A Lalwani wrote:You have not initialized the circle member inside your shape. So, shape.getCircle returns null. When you try to call getName on shape.getCircle, you get a NPE.

You should inject the circle into the shape.



Why should I initialize that? In spring.xml, I think the below line will take care of initialization.



am I right?
 
Ranch Hand
Posts: 491
5
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. With debugger + doc:
There is NO issue with DI autowired byName.
The issue is with the @Around advice code.

2. Read
From Sprimg 4.0.4.RELEASE doc:
8. Aspect Oriented Programming with Spring
Around advice page 204
public class AroundExample

3. See green Comment. You need to return the Object. (Your version did not.)

reply
    Bookmark Topic Watch Topic
  • New Topic