This set of Java Spring Multiple Choice Questions & Answers (MCQs) 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
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
Explanation: In the bean configuration file, all the Spring AOP configurations must be defined inside the aop:config element.
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
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
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
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
Explanation: AspectJ load-time weaving (also known as LTW) happens when the target classes are loaded into JVM by a class loader.
7. How to weave your classes using argument while compiling?
a) -javaagent:CLASSPATH
b) -javaagent:PackgePath
c) -javaweave:CLASSPATH
d) -javaweave:PackagePath
View Answer
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
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
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
Explanation: To use the AspectJ weaver, you need to include the spring-instrument.jar
11. Objects created outside the container:-
a) Domain Objects
b) User Objects
c) SpringVisitor Objects
d) None of the mentioned
View Answer
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
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
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
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.
15. Spring includes AnnotationBeanConfigurerAspect in its aspect library for configuring the dependencies of any objects
a) True
b) False
View Answer
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, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Apply for Programming Internship
- Practice Programming MCQs
- Check Information Technology Books
- Check Spring Books