Debugging a Spring MVC application in standalone JBoss using Eclipse IDE

Though we are not using any database in our application, it would be useful to know that database configuration is done in the file "standalone.xml"
At path: "D:\programfiles\JBoss (For...)\jboss-eap-6.4\standalone\configuration\standalone.xml"

<subsystem xmlns="urn:jboss:domain:datasources:1.2">
<datasources>
<datasource jta="false" jndi-name="java:jboss/datasources/Abc" pool-name="java:jboss/jdbc/Abc" enabled="true" use-ccm="false">
<connection-url>jdbc:oracle:thin:@abc.com:1521/SID</connection-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<driver>ojdbc6</driver>
<security>
<user-name>user_abc</user-name>
<password>password_abc</password>
</security>
</datasource>
<drivers>
<driver name="ojdbc6" module="com.oracle">
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
</driver>
</drivers>
</datasources>
</subsystem>

Code we are using in this example is given at URL: https://www.javatpoint.com/spring-mvc-tutorial

In the image below, we have toggled a break point in Eclipse IDE on at line number '11'.



Line number 12 is line of code running presently.

To debug the application we have to do 'Debug Configurations' from the menu in Eclipse:



In the pop out that will open, do the following configurations:

As the JBoss server we are going to use is standalone, we have to select 'Remote Java Application' and select our application underneath.




Remember the port we have mentioned above, this is the port we would tell JBoss to latch on in debug mode:

D:\programfiles\JBoss (For Local Use)\jboss-eap-6.4\bin>standalone.bat --debug 7777

We will export the WAR file for our application using the 'Export' option in the context menu for the project.
We copy this WAR file at path:
"D:\programfiles\JBoss (For Local Use)\jboss-eap-6.4\standalone\deployments"

Next, run the JBoss server in debug mode.

Port information can be retrieved in two ways:
a) From the server logs:

  • 16:14:19,120 INFO  [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-4) JBWEB003001: Coyote HTTP/1.1 initializing on : http-/127.0.0.1:8090
  • 16:14:19,170 INFO  [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-4) JBWEB003000: Coyote HTTP/1.1 starting on: http-/127.0.0.1:8090

b) From the file "D:\programfiles\J...\jboss-eap-6.4\standalone\configuration\standalone.xml"

  • <socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
  •    ...
  •         <socket-binding name="ajp" port="8009"/>
  •         <socket-binding name="http" port="8090"/>
  •         <socket-binding name="https" port="8443"/>
  • ...
  • </socket-binding-group>


Open the URL for the application in the browser:
"http://localhost:8090/project6_spring_mvc_helloworld/index.jsp"




Clicking on the 'click' button, initiates a call to the controller "HelloWorldController.java", and it will stop at the break-point we had toggled earlier in Eclipse, and you will be taken to the 'Debug' perspective in the Eclipse.



Here on the top-right corner, you can see the values of variables initiated till the line of code being executed till now:




References:

  • http://survival8.blogspot.com/p/blog-page_87.html
  • https://www.javatpoint.com/spring-mvc-tutorial

No comments:

Post a Comment