简体   繁体   中英

How to configure WildFly10.x to able anykind of persistence

I'm learning Java EE, and trying to use JBoss-WildFly server application on my computer for a tiny "Dynamic Web Project" in Eclipse Oxygen (4.7). My goal is just a basic one, I want to have a form in an HTML page on the Internet browser and a database that takes the input and stores it. And maybe a page that would display its content.

I started by installing the version of WildFly 10.1 on my computer. I set the JBOSS_HOME value in my system variables, installed the plugings for Eclipse: "JBoss Tools 4.5.0.AM2" (on tuesday 07/26/2017) from the Marketplace. Configured the runtime environnement with the jdk1.8 path. And started creating my app.

I created the servlet that intercept the first url of the site and deals with calling the right methods if its a POST request and redirecting it if its a GET request to the jsp page, an entity, the jsp page, an EntityDAO and a class that is called by the servlet to do the work of the application (extracting the parameters of the form to set the entity and calling the EntityDAO to create the persistence).

I would like to know how can I set the persistence.xml file (which dataSource to use, what package to call, "hibernate.hbm2ddl.auto" or other?) and how can I configure the server so that it uses mysql or its own database to work properly when all the persistence annotations are set. I don't see much information on how to do that.

I'd recommend you to check out the WildFly's quickstarts for inspiration and for ready to use simple-sample projects that might be always helpful, especially, in cases when you are not sure how to configure particular technology (for Hibernate-5 and Wildfly-10 see quickstart/hibernate5 ).

Note, that each branch corresponds to some wildlfly version as the quickstarts might differ.

Anyway there's pretty much information out there.

Good luck!

I thought I found a solution, but it doesn't work for me... Anyway I do want to post it because maybe it can be the missing piece to someone in the same situation :

So for future comers there's the solution :

First the mysql driver need to be set, if you plan on using it (I only on mysql):

  • Download the MySQL JDBC jar file: "mysql-connector-java-5.1.xx-bin.jar" and copy it to "C:\\wildfly-10.xxFinal\\modules\\mysql\\main". You will have to create the "mysql/main" subdirectory.
  • Then, in the subdirectory "C:\\wildfly-10.xxFinal\\modules\\mysql\\main" create a xml file named "module.xml".
  • Write the following content in :

      <module xmlns:"urn:jboss:module:1.1" name="mysql" slot="main"> <resources> <resource-root path="mysql-connector-java-5.1.xx-bin.jar"/> </resources> <dependencies> <module name="javax.api"/> </dependencies> </module> 
  • (be aware of replacing the x's by the numbers of your own version in all the namefiles I'm giving you...)

Second we need to set the datasource definition :

  • Go to "C:\\wildfly-10.xxFinal\\standalone\\configuration" and open the standalone.xml file
  • Scroll to see the section "subsystem xmlns="urn:jboss:domain:datasources:x.0"" and then add the following in the "datasources" subsection:

      <datasource jndi-name="java:jboss/datasources/MySQLDS" pool-name="MySQLDS" enabled="true" use-java-context="true"> <connection-url>jdbc:mysql://localhost:3306/test</connection-url> <driver>mysql</driver> <pool> <min-pool-size>10</min-pool-size> <max-pool-size>20</max-pool-size> <prefill>true</prefill> </pool> <security> <user-name>root</user-name> <password></password> </security> </datasource> 

(The password is the password you entered when you configured your mysql root account, i left it blank for my part).

  • And finally add to the "drivers" subsection the following content :

      <driver name="mysql" module="mysql"> <driver-class>com.mysql.jdbc.Driver</driver-class> <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class> </driver> 
  • Save and restart the server if it was on, login to the administration console of the server (if you didn't set a "management user" for WildFly, you will have to go to "C:\\wildfly-10.xxFinal\\bin" directory and execute in the command line "add-user.bat", select "a)" for the first question, set a username and a password, and answer no to the following question).

  • Once done, go to the runtime tab of the administration console and search for datasource, for me it was in standalone Server > Subsystems > Datasources > View, you should see the new MySQLDS and you should be able to test it and the result if everything has worked fine should be "success"

For me though I have the error "WFLYJCA0040: failed to invoke operation: WFLYJCA0042: failed to match pool. Check JndiName: java:jboss/datasources/MySQLDS"... I must have done something wrong, somewhere.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM