samedi 21 février 2015

How to start H2 WebServer using Spring without XML?

I am currently using all Spring configurations as annotation and I would like to translate the following to it:



<bean id="h2Server" class="org.h2.tools.Server" factory-method="createTcpServer" init-method="start" destroy-method="stop" depends-on="h2WebServer">
<constructor-arg value="-tcp,-tcpAllowOthers,-tcpPort,9092"/>
</bean>
<bean id="h2WebServer" class="org.h2.tools.Server" factory-method="createWebServer" init-method="start" destroy-method="stop">
<constructor-arg value="-web,-webAllowOthers,-webPort,8082"/>
</bean>


Using the above configuration works perfectly, but since I have nothing else configured using XMLs, I would like to change it as well.


Can anyone please help me with this issue?


EDIT: Using the answer provided, this is the end result:



@Bean(name = "h2WebServer", initMethod="start", destroyMethod="stop")
public org.h2.tools.Server h2WebServer() throws SQLException {
return org.h2.tools.Server.createWebServer("-web", "-webAllowOthers", "-webPort", "8082");
}


@Bean(initMethod="start", destroyMethod="stop")
@DependsOn(value = "h2WebServer")
public org.h2.tools.Server h2Server() throws SQLException {
return org.h2.tools.Server.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort", "9092");
}

Aucun commentaire:

Enregistrer un commentaire