Apache TomEE Cannot Configure DataSource for MySQL

Asked 1 years ago, Updated 1 years ago, 75 views

"I have installed ""apache-tomee-7.0.3-plume"" and it works in conjunction with Eclipse."
I tried to set up and use MySQL DataSource, but it only reads the default HSQLDB.
After reading the TomEE documentation, I wrote about the DataSource configuration as follows:
There is no problem with launching MySQL, the existence of the test database, or configuration.

<Resource id="MySQLDB" type="DataSource">
    JdbcDriver com.mysql.jdbc.Driver
    JdbcUrl jdbc:mysql://localhost/test
    UserName root
    Password mysql
</Resource>

The documentation states that it should be written either in the TomEE installation directory "conf/tomee.xml" or in the web application "WEB-INF/conf/resources.xml" and I tried both.
The JDBC Driver is located in both the "lib" in the TomEE installation directory and the "WEB-INF/lib" under the web application.
We also changed the location of Eclipse's server by referring to Post which is facing similar issues.
However, they would not read the DataSource configured, and the results of the simple code below would show "DB:HSQL Database Engine" and the default HSQLDB would be used as the DataSource.

@Resource(name="MySQLDB")
private DataSources;
・・・
System.out.println("DB:"+ds.getConnection().getMetaData().getDatabaseProductName());

In the log, "Information: Creating Resource (id=My DataSource)" appears, and the MySQLB DataSource that you configured is not created.No exceptions have occurred.

I looked up the information on the Internet, but it's stuck.
If anyone knows anything, please let me know.

java-ee

2022-09-30 14:31

1 Answers

JdbcDriver com.mysql.jdbc.Driver

It is written as shown in , but official document has =.

<Resource id="MySQLDB" type="DataSource">
    JdbcDriver=com.mysql.jdbc.Driver
    JdbcUrl=jdbc:mysql://localhost/test
    UserName = root
    Password = mysql
</Resource>


2022-09-30 14:31

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.