Hi I am relatively new to spring. Am using Annotations. My doubt begin I have a class as
public class MyClassA{
@Autowired
private MyClassB variableClassB;
// more code here
.
.
.
in my applicationContext.xml
<context:component-scan base-package="package containing MyClassB" />
My question being do I need to add bean declaration in applicationContext.xml as follows
<bean id="classB" class="com.MyClassB"
or is it sufficient to have @Autowired annotation
No it is not.
If your MyClassB
is annotated with annotations like @Component
, @Service
, @Repository
or @Controller
the component scan will create a bean for the class in the bean factory.
If you are not using any of these annotations then, you need to create a bean manually as you have given
Ex:
@Component
public class MyClassB{
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments