I am moving on to some existing xml configuration to Java configuration for Spring. During this process, I came across some transferred Java code that produces verification code Exception.
Exception
@Bean public PoolDataSource myDataSource() { final PoolDataSource dataSource = PoolDataSourceFactory.getPoolDataSource(); dataSource.setConnectionPoolName("myDataSourcePoolName"); // throws SQLException return dataSource; }
I was wondering how I could handle this, and whether the Spring developers had any “best practices”.
Should I mark the method with a sentence throws(which will propagate any chain @Import), or should I process it with a block try- catch?
throws
@Import
try
catch
In general, you should simply declare any checked exceptions in the throwsmethod clause @Bean.
@Bean
, " @Import"; throws, , @Bean, , , throws, , , Spring , beans, Spring XML. @Import .