Posts

Showing posts from 2024

@Primary In Spring Framework

 @Primary In Spring Framework @Primary @Bean (name = "jdbcMainNamedParameterJdbcTemplate" ) public NamedParameterJdbcTemplate namedParameterJdbcTemplate () { return new NamedParameterJdbcTemplate(dataSource()) ; } @Bean (name = "jdbcMainNamedParameterJdbcTemplateForReplica" ) public NamedParameterJdbcTemplate namedParameterJdbcTemplateForReplica () { return new NamedParameterJdbcTemplate(dataSourceForReplica()) ; In Spring Framework, @Primary is an annotation used to indicate a primary bean when multiple beans of the same type are present. When you have more than one bean of the same type, Spring needs to know which one to inject where. The @Primary annotation tells Spring that a particular bean should be given preference when there are multiple candidates. In your code snippet, you have two beans of type NamedParameterJdbcTemplate : jdbcMainNamedParameterJdbcTemplate jdbcMainNamedParameterJdbcTemplateForReplica Both beans are of the same type, so if you in...

Protocol Buffers with Java & Gradle

Image