How to read properties file to configure JPA?

1

I have a .properties file to set up the bank for my project. But I can not read the file.

Does anyone give 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();
}   

Properties file

jdbc.user=root
jdbc.password=
jdbc.url=jdbc:mysql://localhost/almoxarifadome"
jdbc.driver=com.mysql.jdbc.Driver
    
asked by anonymous 09.08.2016 / 14:31

1 answer

0

Try this:

InputStream is = null;
Properties p = new Properties();

is = EntityManagerProducer.class.getClassLoader().getResourceAsStream('conexao.properties');
p.load(is);

Source: link

    
09.08.2016 / 14:42