@startup and @postConstruct not called at payara startup

909 views Asked by At

I am developing a JEE application and I want to do some migration when the application starts. Actually, I am using payara-micro with Docker as a server. For an unknown reason, this code is never executed.

Here is my code :

@Singleton
@Startup
public class FlywayMigration {


    @PostConstruct
    public void startMigration(){
      System.out.println("Starting flyway migration");
    }
} 

I added the javaee-api as dependency in my pom :

    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>

Here is the content of my Dockerfile :

FROM payara/micro

COPY ./target/mywebapp.war $DEPLOY_DIR

After building and running the docker image, the logs of the application shows that the app started well :

Payara Micro URLs
http://5b258e6a441a:8080/mywebapp

'mywebapp' REST Endpoints
 GET    /mywebapp/api/hello
 GET    /mywebapp/api/myresource

Can anyone help me find a solution ?

1

There are 1 answers

0
Dimitri On BEST ANSWER

I finally make it work. The problem is that I was using the bad @Singleton annotation. Instead of using @javax.ejb.Singleton I used to @javax.inject.Singleton.