How to read properties file to configure JPA?

Asked

Viewed 365 times

1

I have a file . properties to configure my project’s database. However, I cannot read the file.

Someone gives a force?

Entitymanagerproducer

@ApplicationScoped
public class EntityManagerProducer {

private EntityManagerFactory factory;

public EntityManagerProducer() throws FileNotFoundException, IOException {
    Properties p = new Properties();

    p.load(new FileInputStream("./conexao.properties"));


    factory = Persistence.createEntityManagerFactory("AlmoxarifadoPU");
}

@Produces @RequestScoped
public EntityManager createEntityManager() {
    return factory.createEntityManager();
}

public void closeEntityManager(@Disposes EntityManager manager) {
    manager.close();
}   

File properties

jdbc.user=root
jdbc.password=
jdbc.url=jdbc:mysql://localhost/almoxarifadome"
jdbc.driver=com.mysql.jdbc.Driver
  • where this located this archive connexion.properties ? in Resources? why not use the default JPA(persistence.xml) ?

1 answer

0

  • It didn’t work out that way

  • Post the mistake you made.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.