Spring Questions and Answers – AspectJ Aspects

«
»

This set of Java Spring Interview Questions and Answers focuses on “AspectJ Aspects”.
1. Tag used to enable AspectJ annotation?
a) Introduction
b) aop:aspectj-autowire
c) aop:aspectj-autoproxy
d) AfterSpecial
View Answer

Answer: c
Explanation: To enable AspectJ annotation support in Spring, you have already defined an empty XML element, aop:aspectj-autoproxy.

2. Tag which defined Spring AOP configurations
a) aop:config
b) aop:configregister
c) aop:configbeans
d) None of the mentioned
View Answer

Answer: a
Explanation: In the bean configuration file, all the Spring AOP configurations must be defined inside the aop:config element.

advertisement

3. What are the ways to declare an advice?
a) pointcut-ref attribute
b) pointcut attribute
c) all of the mentioned
d) none of the mentioned
View Answer

Answer: c
Explanation: An advice element requires either a pointcut-ref attribute to refer to a pointcut or a pointcut attribute to embed a pointcut expression directly.

4. Applying aspects to your target objects
a) AspectJ Annotation
b) Weaving
c) All of the mentioned
d) None of the mentioned
View Answer

Answer: b
Explanation: Weaving is the process of applying aspects to your target objects.

5. Special compiler used during weaving
a) jvm
b) gcc
c) ajc
d) none of the mentioned
View Answer

Answer: c
Explanation: AspectJ compile-time weaving is done through a special AspectJ compiler called ajc.

6. Name of the process when targe classes are loaded into JVM
a) load-time weaving
b) process-time weaving
c) load-process weaving
d) process-delivery weaving
View Answer

Answer: a
Explanation: AspectJ load-time weaving (also known as LTW) happens when the target classes are loaded into JVM by a class loader.
advertisement

7. How to weave your classes using argument while compiling?
a) -javaagent:CLASSPATH
b) -javaagent:PackgePath
c) -javaweave:CLASSPATH
d) -javaweave:PackagePath
View Answer

Answer: a
Explanation: You need only to add a VM argument to the command that runs your application. Then your classes will get woven when they are loaded into the JVM.

8. XML Element to include load-time weaver
a) aop:config
b) aop:auto-wire
c) context:load-time-weaver
d) aop:load-time-weaver
View Answer

Answer: c
Explanation: To turn on a suitable load-time weaver for your Spring application, you need only to declare the empty XML element context:load-time-weaver.

9. You also have to include suitable load-time weaver’s configuration in XML
a) True
b) False
View Answer

Answer: b
Explanation: Spring will be able to detect the most suitable load-time weaver for your runtime environment.

10. Library to use AspectJ weaver
a) spring-instrument.jar
b) spring-introduction.jar
c) spring-aop.jar
d) spring-weave.jar
View Answer

Answer: a
Explanation: To use the AspectJ weaver, you need to include the spring-instrument.jar
advertisement

11. Objects created outside the container:-
a) Domain Objects
b) User Objects
c) SpringVisitor Objects
d) None of the mentioned
View Answer

Answer: a
Explanation: Objects created outside the Spring IoC container are usually domain objects. They are often created using the new operator or from the results of database queries.

12. How to inject Spring bean into domain objects
a) AOP
b) XML
c) AspectJ
d) Java Based
View Answer

Answer: a
Explanation: To inject a Spring bean into domain objects created outside Spring, you need the help of AOP.

13. We can directly use Spring AOP for injection of beans
a) True
b) False
View Answer

Answer: b
Explanation: As the domain objects are not created by Spring, you cannot use Spring AOP for injection.

14. Which scope does @Configurable instantiated class looks for?
a) Singleton
b) Prototype
c) None of the mentioned
d) All of the mentioned
View Answer

Answer: b
Explanation: When a class with the @Configurable annotation is instantiated, the aspect will look for a prototype-scoped bean definition whose type is the same as this class.

advertisement

15. Spring includes AnnotationBeanConfigurerAspect in its aspect library for configuring the dependencies of any objects
a) True
b) False
View Answer

Answer: a
Explanation: Spring includes AnnotationBeanConfigurerAspect in its aspect library for configuring the dependencies of any objects, even if they were not created by the Spring IoC container. First of all, you have to annotate your object type with the @Configurable annotation to declare that this type of object is configurable.

Sanfoundry Global Education & Learning Series – Java Spring.
To practice all areas of Java Spring for Interviews, here is complete set of 1000+ Multiple Choice Questions and Answers.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn