The above code shows a conditional @Bean method for the creation of a JdbcTemplate bean. Which two statements correctly describe the code behavior? (Choose two.)
A.
@ConditionalOnBean(name= “dataSource”) should be replaced with @ConditionalOnBean (DataSource.class) for greater flexibility.
B.
@ConditionalOnBean(name= “dataSource”) should be replaced with @ConditionalOnMissingBean (DataSource.class) for greater flexibility.
C.
The @Bean annotation should be removed.
D.
A JdbcTemplate bean will be created when the DataSource class is in the classpath but there is no DataSource bean.
E.
A JdbcTemplate bean will be created when a bean named dataSource has already been created.
A and E
Option D is incorrect because the @ConditionalOnBean annotation requires that a bean with the specified name or class already exists in the application context for the JdbcTemplate bean to be created.
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
rhuanca
Highly Voted 10 months, 2 weeks agoEymet
Most Recent 3 months, 3 weeks agoqqoo
6 months, 4 weeks agozakupower
11 months ago