Prev Next

Spring / Spring Beans

Explain @Required annotation in Spring framework.

The @Required annotation applies to bean property setter methods and it indicates that the represented bean property is required and must be initialized in XML configuration file at configuration time otherwise the container will throw a BeanInitializationException exception.

public class Employee {
   private Integer age;
   private String name;
  public Integer getAge() {
      return age;
   } @Required
   public void setAge(Integer age) {   this.age = age;
   }
}

The RequiredAnnotation BeanPostProcessor bean post processor checks if all the bean properties with the @Required annotation have been set. To enable this bean post processor, you must register it in the Spring IoC container.

<bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor" />

It's right time to invest in Cryptocurrencies Dogecoin! Earn free bitcoins up to $250 now by signing up.

Earn bitcoins upto $250 (free), invest in other Cryptocurrencies when you signup with blockfi. Use the referral link: Signup now and earn!

Using BlockFi, don't just buy crypto - start earning on it. Open an interest account with up to 8.6% APY, trade currencies, or borrow money without selling your assets.


Join CoinBase! We'll both receive $10 in free Bitcoin when they buy or sell their first $100 on Coinbase! Available in India also. Use the referral Join coinbase!


Invest now!!! Get Free equity stock (US, UK only)!

Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.

The Robinhood app makes it easy to trade stocks, crypto and more.


Webull! Receive free stock by signing up using the link: Webull signup.

More Related questions...

What are Beans in Spring framework? What does a Spring Bean definition consists of? Different Spring Bean Scope. How do I provide beans configuration metadata to the Spring Container? How do I define the scope of a bean in spring framework? Describe the lifecycle of a Bean in Spring framework. Is a singleton bean thread safe in Spring Framework? Explain the important life-cycle methods of a bean in Spring framework. Explain inner beans in Spring framework? What are the limitations of autowiring in Spring framework? How do I inject java.util.Properties into a Spring Bean? Explain @Required annotation in Spring framework. Explain @autowired annotation in spring framework. How do I make autowired bean property as optional? What is @Resource annotation in Spring framework? How do I configure a bean in my spring application? What kind of exception does spring DAO classes throw? Explain the different ways to configure a Java class as Spring Bean. Difference between id and name attribute of <bean> element in a Spring configuration file. Is Spring Bean with singleton scope thread safe? Difference between @Resource and @Autowired in Spring framework. Explain lazy-init attribute of bean tag in Spring. Can we fetch the inner bean from spring container using its id, if an inner bean defines one? Explain Spring bean inheritance. What is Bean Definition Template in Spring framework? What is spring bean pure inheritance template? Can a spring bean tag with no id or name attribute be created? How do I inject value for a bean property of primitive type? Can spring bean autowire on primitive types? How do I create a stateful bean in Spring framework? Difference between request and prototype bean scope in spring? What is the role of a Spring bean configuration file? Explain Circular Dependency scenario in Spring. Spring Bean marked as abstract by abstract=true needs the corresponding java class be abstract ? Spring Bean: Specify particular implementation of collection in your bean definition. Spring bean: difference between stateless and stateful beans. Can I define spring bean twice with same name in different bean definition file? Can I define spring bean twice with the same bean id in same file? Explain JSR-250 annotation. What is primary annotation in Spring? How to get all the Spring beans implementing a specific interface? What are the attributes of Spring @Transactional annotation? When is a spring bean destroy-method being called? When is a Spring Singleton bean garbage collected? When is a prototype bean garbage collected? Explain BeanPostProcessor beans. Explain no autowiring mode in spring bean. How do you debug Spring configuration? What is component scan in Spring framework?
Show more question and Answers...

Spring Interview questions II

Comments & Discussions