Open
Description
How to migrate to such kind of declaring sonfig as fu
offers??
It is non-intuitive (for me)
Say having config
@Configuration
@EnableAsync
@EnableScheduling
public class AsyncConfiguration implements AsyncConfigurer {
private final Logger log = LoggerFactory.getLogger(AsyncConfiguration.class);
private final JHipsterProperties jHipsterProperties;
public AsyncConfiguration(JHipsterProperties jHipsterProperties) {
this.jHipsterProperties = jHipsterProperties;
}
@Override
@Bean(name = "taskExecutor")
public Executor getAsyncExecutor() {
log.debug("Creating Async Task Executor");
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(jHipsterProperties.getAsync().getCorePoolSize());
executor.setMaxPoolSize(jHipsterProperties.getAsync().getMaxPoolSize());
executor.setQueueCapacity(jHipsterProperties.getAsync().getQueueCapacity());
executor.setThreadNamePrefix("cip-old-Executor-");
return new ExceptionHandlingAsyncTaskExecutor(executor);
}
@Override
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
return new SimpleAsyncUncaughtExceptionHandler();
}
}
and
@Configuration
@EnableJpaRepositories("com.psg.cip.repository")
@EnableJpaAuditing(auditorAwareRef = "springSecurityAuditorAware")
@EnableTransactionManagement
@EnableElasticsearchRepositories("com.psg.cip.repository.search")
public class DatabaseConfiguration {
private final Logger log = LoggerFactory.getLogger(DatabaseConfiguration.class);
private final Environment env;
private final CacheManager cacheManager;
public DatabaseConfiguration(Environment env, CacheManager cacheManager) {
this.env = env;
this.cacheManager = cacheManager;
}
/**
* Open the TCP port for the H2 database, so it is available remotely.
*
* @return the H2 database TCP server
* @throws SQLException if the server failed to start
*/
@Bean(initMethod = "start", destroyMethod = "stop")
@Profile(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)
public Object h2TCPServer() throws SQLException {
try {
// We don't want to include H2 when we are packaging for the "prod" profile and won't
// actually need it, so we have to load / invoke things at runtime through reflection.
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Class<?> serverClass = Class.forName("org.h2.tools.Server", true, loader);
Method createServer = serverClass.getMethod("createTcpServer", String[].class);
return createServer.invoke(null, new Object[]{new String[]{"-tcp", "-tcpAllowOthers"}});
} catch (ClassNotFoundException | LinkageError e) {
throw new RuntimeException("Failed to load and initialize org.h2.tools.Server", e);
} catch (SecurityException | NoSuchMethodException e) {
throw new RuntimeException("Failed to get method org.h2.tools.Server.createTcpServer()", e);
} catch (IllegalAccessException | IllegalArgumentException e) {
throw new RuntimeException("Failed to invoke org.h2.tools.Server.createTcpServer()", e);
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
if (t instanceof SQLException) {
throw (SQLException) t;
}
throw new RuntimeException("Unchecked exception in org.h2.tools.Server.createTcpServer()", t);
}
}
@Bean
public SpringLiquibase liquibase(@Qualifier("taskExecutor") TaskExecutor taskExecutor,
DataSource dataSource, LiquibaseProperties liquibaseProperties) {
// Use liquibase.integration.spring.SpringLiquibase if you don't want Liquibase to start asynchronously
SpringLiquibase liquibase = new AsyncSpringLiquibase(taskExecutor, env);
liquibase.setDataSource(dataSource);
liquibase.setChangeLog("classpath:config/liquibase/master.xml");
liquibase.setContexts(liquibaseProperties.getContexts());
liquibase.setDefaultSchema(liquibaseProperties.getDefaultSchema());
liquibase.setDropFirst(liquibaseProperties.isDropFirst());
if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_NO_LIQUIBASE)) {
liquibase.setShouldRun(false);
} else {
liquibase.setShouldRun(liquibaseProperties.isEnabled());
log.debug("Configuring Liquibase");
}
return liquibase;
}
}
how to "translate" this to fu
?