0

I decited to build a spring boot app using javafx. And I want to have a "light" database. I selected a HSQL database. The problem is when I run my database in powershell

java -cp .\hsqldb-2.6.1.jar org.hsqldb.Server --database bazaX

then my database is turn on and my spring app works fine. But when I dont turn on my database by that script, it won't work. Can I somehow execute that script before a springboot app start? And what is the best/the easiest way.

Maybe some can help you: 1.Command in Powershell:

PS C:\Users\knapi\IdeaProjects\demo1\myAppSpring\database> java -cp .\hsqldb-2.6.1.jar org.hsqldb.Server --database bazaX [Server@76707e36]: Startup sequence initiated from main() method [Server@76707e36]: Could not load properties from file [Server@76707e36]: Using cli/default properties only [Server@76707e36]: Initiating startup sequence... [Server@76707e36]: Server socket opened successfully in 4 ms. [Server@76707e36]: Database [index=0, id=0, db=file:bazaX, alias=] opened successfully in 233 ms. [Server@76707e36]: Startup sequence completed in 274 ms. [Server@76707e36]: 2022-11-12 13:52:01.856 HSQLDB server 2.6.1 is online on port 9001 [Server@76707e36]: To close normally, connect and execute SHUTDOWN SQL [Server@76707e36]: From command line, use [Ctrl]+[C] to abort abruptly

my hsqlConfigFile.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
        <bean id="hqlServer" class="org.hsqldb.server.Server" init-method="start" destroy-method="stop">
            <property name="properties"><bean class="org.hsqldb.persist.HsqlProperties">
                <constructor-arg><props>
                    <prop key="server.database.0">file:bazaX</prop>
                    <prop key="server.dbname.0">bazaX</prop><!--DB name for network connection-->
                    <prop key="server.no_system_exit">true</prop>
                    <prop key="server.port">9001</prop><!--default port is 9001 -->
                </props></constructor-arg>
            </bean></property>
        </bean>
    </beans>

my main file:

    import javafx.application.Application;
    import javafx.fxml.FXMLLoader;
    import javafx.scene.Parent;
    import javafx.scene.Scene;
    import javafx.stage.Stage;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.context.event.ApplicationReadyEvent;
    import org.springframework.context.ConfigurableApplicationContext;
    import org.springframework.context.annotation.ImportResource;
    import org.springframework.context.event.ContextRefreshedEvent;
    import org.springframework.context.event.EventListener;
    
    @SpringBootApplication
    @ImportResource(value="classpath:/hsqlConfigFile.xml")
    public class MyAppSpringApplication extends Application {
    
        private ConfigurableApplicationContext springContext;
        private FXMLLoader fxmlLoader;
    
        public static void main(String[] args) {
            Application.launch(args);
        }
    
        @Override
        public void start(Stage stage) throws Exception {
            fxmlLoader.setLocation(getClass().getResource("/sample.fxml"));
            Parent root = fxmlLoader.load();
            stage.setTitle("Sample app");
            Scene scene = new Scene(root);
            stage.setScene(scene);
            stage.show();
        }
    
        @Override
        public void stop() throws Exception {
            springContext.stop();
        }
    
        @Override
        public void init() throws Exception {
            springContext = SpringApplication.run(MyAppSpringApplication.class);
            fxmlLoader = new FXMLLoader();
            fxmlLoader.setControllerFactory(springContext::getBean);
        }
    }

And erros are in files. https://drive.google.com/drive/folders/1YnxLWAXhDz-xF95Lu1OXgRU2bYdanOv1?usp=share_link

0 Answers0