Spring classic interview questions, sorted out for you! (Full version with answers)

23. What are the limitations of automatic assembly?

Possibility of overwriting-you can always use and set specified dependencies, which will overwrite autowiring.
Basic metadata types-simple attributes (such as original data types, strings, and classes) cannot be automatically assembled.
Confusing nature-always prefer to use explicit assembly, because automatic assembly is not very precise.

24. What important Spring annotations have you used?

@Controller-The controller class used in Spring MVC projects.
@Service-for service classes.
@RequestMapping-Used to configure URI mapping in the controller handler method.
@ResponseBody-used to send Object as response, usually used to send XML or JSON data as response.
@PathVariable-Used to map dynamic values ​​from URI to handler method parameters.
@Autowired-Used to autowire dependencies in spring beans.
@Qualifier-Use @Autowired annotation to avoid confusion when there are multiple bean type instances.
@Scope-Used to configure the scope of spring beans.
@Configuration, @ComponentScan and @Bean-for java-based configuration.
@Aspect, @Before, @After, @Around, @Pointcut-for aspect programming (AOP)

25. How to start annotation assembly in spring?

By default, annotation assembly is not turned on in the Spring container. Therefore, to use annotation-based assembly, we must enable it in the Spring configuration file by configuring the <context:annotation-config /> element.

26. What is the difference between @Component, @Controller, @Repository, and @Service?

@Component: This marks the java class as bean. It is a general stereotype for any Spring management component. Spring's component scanning mechanism can now pick it up and pull it into the application environment.
@Controller: This marks a class as a Spring Web MVC controller. Beans marked with it will be automatically imported into the IoC container.
@Service: This annotation is a specialization of component annotations. It does not provide any other behavior for the @Component annotation. You can use @Service instead of @Component in the service layer class because it specifies the intent in a better way.
@Repository: This annotation is a specialization of the @Component annotation with similar uses and functions. It provides additional benefits for DAO. It imports the DAO into the IoC container and makes unchecked exceptions eligible to be converted to Spring DataAccessException.

27. What is the use of @Required annotation?

@Required is applied to bean property setter methods. This annotation only indicates that you must use explicit property values ​​in the bean definition or use autowiring to populate the affected bean properties during configuration. If the affected bean properties have not been populated, the container will throw a BeanInitializationException.

28. What is the use of @Autowired annotation?

@Autowired can more accurately control where and how the automatic assembly should be performed. This annotation is used to automatically assemble beans on setter methods, constructors, properties or methods with arbitrary names or multiple parameters. By default, it is type-driven injection.

29. What is the use of @Qualifier annotation?

When you create multiple beans of the same type and want to assemble only one of the beans using attributes, you can use the @Qualifier annotation and @Autowired to disambiguate by specifying which exact bean should be assembled.

30. What is the use of @RequestMapping annotation?

The @RequestMapping annotation is used to map a specific HTTP request method to a specific class/method in the controller that will process the corresponding request. This annotation can be applied to two levels:
class level: mapping request URL
method level: mapping URL and HTTP request method

31. What is the use of spring DAO?

Spring DAO makes it easier for data access technologies such as JDBC, Hibernate or JDO to work in a unified way. This makes it easy for users to switch between persistence technologies. It also allows you to write code without having to think about catching the different exceptions of each technology.

32. What classes exist in the spring JDBC API?

JdbcTemplate
SimpleJdbcTemplate
NamedParameterJdbcTemplate
SimpleJdbcInsert
SimpleJdbcCall

Reader benefits

Thank you for seeing here!
I have compiled a lot of 2020 latest Java interview questions (including answers) and Java study notes here, as shown below
Insert picture description here

The answers to the above interview questions are organized into document notes. As well as interviews also compiled some information on some of the manufacturers & interview Zhenti latest 2020 collection (both documenting a small portion of the screenshot) free for everyone to share, in need can click to enter signal: CSDN! Free to share~

If you like this article, please forward it and like it.

Remember to follow me!

Guess you like

Origin blog.csdn.net/weixin_49527334/article/details/112428205