WildFly 12 and Java 10 does not recognize annotations - java

What I Have
Tomcat 9.0.7
WildFly 12.0.0
JDK 10
Maven 3.5.3
Relevant Files
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.training</groupId>
<artifactId>BigVoiceWebApp</artifactId>
<name>BigVoiceWebApp Maven Webapp</name>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<url>http://maven.apache.org</url>
<properties>
<maven.compiler.source>1.10</maven.compiler.source>
<maven.compiler.target>1.10</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<!-- <build>
<finalName>${project.artifactId}</finalName>
</build>-->
<profiles>
<profile>
<id>release-profile</id>
<build>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<finalName>BigVoiceWebApp</finalName>
</build>
</project>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<display-name>Archetype Created Web Application</display-name>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/PostgresDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
My Problem
I have servlets like this:
#WebServlet(name = "MemberController", urlPatterns = {"/MemberController"})
#MultipartConfig
public class MemberController extends HttpServlet {
The problem now, WildFly somehow does not obey annotations. When I access the URL, this is what I got in my browser (copied by viewing source HTML):
<html>
<head><title>Error</title></head>
<body>Not Found</body>
</html>
I have to declare everything in web.xml (adding to previous file) for what I've declared as annotations.
<servlet>
<servlet-name>Test</servlet-name>
<servlet-class>com.example.training.controller.MemberController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/MemberController</url-pattern>
</servlet-mapping>
When I reupload the exact same WAR file to Tomcat, the annotations are read correctly.
My question is, why? And how to make WildFly recognize those annotations?

Thanks for the file. It's Java 10. I noticed during the build I get:
[INFO] --- maven-war-plugin:2.2:war (default-war) # SampleForError ---
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.thoughtworks.xstream.core.util.Fields (file:/home/scott/.m2/repository/com/thoughtworks/xstream/xstream/1.3.1/xstream-1.3.1.jar) to field java.util.Properties.defaults
WARNING: Please consider reporting this to the maintainers of com.thoughtworks.xstream.core.util.Fields
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
A similar warning is produced when Wildfly starts up. Some combination of Wildfly 12 and Java 10 doesn't work right in JEE7 mode.
However, there are multiple workarounds. If you run Wildfly in EE8 Preview Mode then it works. Do this by running either bin/standalone.sh -Dee8.preview.mode=true or bin/standalone.sh -c standalone-ee8.xml
Otherwise, this works without any changes in Java 8.
As an aside, you're trying very hard to confuse any container you're running in. You specify servlet spec 4 in your pom.xml but then your web.xml is:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
So your web.xml tells the container that you're using Servlet spec 2.3. If you really need servlet spec 4.0 then your web.xml should be something like:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
</web-app>

Related

Exposing Resources using Tomcat Server

After debugging for a few hours, I am seeking help to set up a REST API using Jersey in Java. I am using a Tomcat 6 server and the following is my file structure of the Mavin project:
On the right, the resource which I want to expose can be seen.
For the web.xml I have a file as follows:
<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
see implementation details https://github.com/jax-rs -->
<web-app version="2.5">
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.howtodoinjava.demo</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/webapi/*</url-pattern>
</servlet-mapping>
</web-app>
and for the pom.xml as follows:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.howtodoinjava.demo</groupId>
<artifactId>JerseyArcheTypeDemo</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>JerseyDemo</name>
<build>
<finalName>JerseyArcheTypeDemo</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<!-- uncomment this to get JSON support
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
-->
</dependencies>
<properties>
<jersey.version>2.20</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
I can build the Maven project and start the server. However if I want to add resources to the Server by right-clicking on the server name and clicking on "Add or Remove..." I get a message that I cannot select any resources. I followed the adivce in this question: There are No resources that can be added or removed from the server but it did not help and I also do not get any error messages which could lead me. Any recommendation what I am doing wrong?
When I want to run the Resource on the server by selecting "Run As" and then "Run on Server" I get the following message: The selection cannot be run on the server.
You can't select this project because Tomcat 6 does not support Servlet 4.0 projects. Servlet 4.0 requires Tomcat 9.x, which itself requires Java 1.8. See the Tomcat documentation.
You can lower the facet version, but it makes far more sense to simply use the newer Tomcat version. Tomcat 6 is far past its end-of-life.

Wildfly server running, but returning 404 error Not found no matter what I do

I followed a REST API | Web service tutorial on the web and got stuck midway. When I run the server it setups successfully, shows that its running at http://localhost:8080/ as well but as soon as I try to access different servlets, the page reloads and returns with 404 Error Not found. I tried downloading earlier versions of wildfly with no avail. The paths I tried were /demorest, /webapi, /myresources and they were used in conjunction as well.
What could be the problem?
package com.david.demorest;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
#Path("myresource")
public class MyResource {
#GET
#Produces(MediaType.TEXT_PLAIN)
public String getIt() {
return "Got it!";
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html -->
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.david.demorest</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/webapi/*</url-pattern>
</servlet-mapping>
</web-app>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.david</groupId>
<artifactId>demorest</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>demorest</name>
<build>
<finalName>demorest</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<inherited>true</inherited>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-binding</artifactId>
</dependency>
</dependencies>
<properties>
<jersey.version>3.0.4</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
It's likely that the tutorial is written to deploy to Tomcat. Wildfly has everything you need for JaxRS built in.
To get started you will need three files. First, you need a class that extends javax.ws.rs.core.Application. It can be in any package you'd like:
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
#ApplicationPath("/rest")
public class RestApplicationConfig extends Application {
// intentionally empty
}
Next, you need your service. The one you show should work though I'd have my Path start with a forward slash like #Path("/myresource"). Lastly, you need a pom.xml that produces a war file. I haven't tested yours but I have one that looks like:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>jaxrs-simple-sample</artifactId>
<groupId>com.hotjoe.jaxrs</groupId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
</plugin>
</plugins>
</build>
</project>
That I just verified works. Once you have all of this you can produce a war file that can be dropped into $WILDFLY_HOME/standalone/deployments and Wildfly will run it. But you need to watch the URL. As defined in my pom.xml this will create a war file named jaxrs-simple-sample-1.0-SNAPSHOT.war and this file name becomes part of the URL. In this example, the URL to your service would be http://localhost:8080/jaxrs-simple-sample-1.0-SNAPSHOT/rest/myresource. The rest part of that comes from the #ApplicationPath defined. But the other part comes from the name of the war. If you don't like that, you can add one more Wildfly specific file:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<context-root>myapp</context-root>
</jboss-web>
This file, in a standard Maven environment, would be named jboss-web.xml and would be placed in src/main/webapp/WEB-INF. This would change the above URL to http://localhost:8080/myapp/rest/myresource.

Eclipse - Maven project with Tomcat receives 404 Error

I go over the internet to figure it out why I receive 404 I tried almost all solutions and didn't help. I have:
Eclipse Photom
Tomcat 9
Java version 1.8
Maven project using Jersey 2.27
When I hit http://localhost:8080/Test/rest/testservice I got 404 "Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists."
POM.XML
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Test</groupId>
<artifactId>com.test</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>com.test Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
<finalName>com.test</finalName>
</build>
</project>
WEB.XML
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>Test Jersey Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.test</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Test Jersey Service </servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
PROJECT STRUCTURE AND JAVA CLASS
I Have added in Deployment Assembly -> Maven Dependencies also
I solved it. So if anyone experience problems with 404 even the fact that you did everything right then double check these steps:
Always save (CTR + S) pom.xml and web.xml when you make any kind of
modifications
Replace index.jsp with index.html
Right click the project go to Maven -> Update Project
Right click the project go to Run as -> Run on Server (if I run it
manually it doesn't work, but when I go from run as it is working
correctly)
I have created a tutorial with step by step. If anyone wanted please contact me.

HTTP Status 500 - Servlet.init() for servlet fitTrackerServlet threw exception

This is my first time working with Spring and I am following the tutorial on PluralSight. Running the first example, I run into the error that is listed in the title. In my console, I get errors like these. I am using older versions of the dependencies to go through this course. I've made sure to follow the tutorial closely so not sure if I messed up somewhere or something is deprecated. I am using http://localhost:8080/FitnessTracker/greeting.html
SEVERE: Context initialization failed
java.lang.IllegalArgumentException
SEVERE: StandardWrapper.Throwable
java.lang.IllegalArgumentException
SEVERE: Allocate exception for servlet fitTrackerServlet
java.lang.IllegalArgumentException
HelloController.java
package com.pluralsight.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
public class HelloController {
#RequestMapping(value = "/greeting")
public String sayHello(Model model) {
model.addAttribute("greeting", "Hello World");
return "hello";
}
}
servlet-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<mvc:annotation-driven />
<context:component-scan base-package="com.pluralsight.controller" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/>
</beans>
hello.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>${greeting}</h1>
</body>
</html>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>fitTrackerServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/servlet-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>fitTrackerServlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<display-name>Archetype Created Web Application</display-name>
</web-app>
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pluralsight</groupId>
<artifactId>FitnessTracker</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>FitnessTracker Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>FitnessTracker</finalName>
</build>
</project>
I had the same problem with the same PluralSight tutorial. I had both Java 1.7 and Java 1.8 installed. The project apparently throws an exception with Java 1.8. To rectify this situation you need to ensure that your Spring STS environment is set to use Java 1.7.
Right click on the project and select Properties.
In the Properties dialog, select Java Compiler.
At the bottom of the dialog, select the link to configure the Installed JREs.
Add a definition to point to JRE 1.7 and select this as the default.
The PluralSight tutorial now works for me. I am beginner to Java and Spring MVC myself so I am not sure if this was the best way to solve the problem.
Well, spring 3.2 needs java 7 or earlier. Instead of changing project properties, one another solution is just change the version number of spring mvc in pom.xml to 4.2.4.RELEASE instead of 3.2.0.RELEASE that you have used earlier.
Now, you can proceed normally with java 8.
Below, I show the whole pom.xml with only change that I mentioned above.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pluralsight</groupId>
<artifactId>FitnessTracker</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>FitnessTracker Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>
</dependencies>
<build>
<finalName>FitnessTracker</finalName>
</build>
</project>
Try with 4.1.5. It works for me.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
Try to use 3.2.3.RELEASE version wherever you have spring based dependency
I faced the same issue.
So what you have to do is to use Tomcat v7.0,
It is because I was using Tomcat v9.0 and it does not work with JRE7 but JRE8.
So
Set your application with Tomcat v7.0 and set your STS or Eclipse default build path with JRE7 .
Restart your Tomcat server.
Go to your browser and paste the above link and Here you Go !!! :)
To fix this, simply change your servlet container's runtime environment to Java 7. In Eclipse:
Preferences -> Server -> Runtime Environments
Select the server you are running the project under and click Edit....
From the JRE section, select the Java 7 JRE. Note that in order to be able to do this, you first need to download and install Java 7, and make the Java 7 JRE available in Eclipse. To make Java 7 JRE available in Eclipse:
Download Java 7 and install it.
In Eclipse, select Preferences -> Java -> Installed JREs and click Search.... If you have installed Java 7 to its default path, Eclipse should be able to discover Java 7 automatically.
After adding Java 7 to Eclipse, you can select JRE 7 as the runtime environment of your servlet container.
I would also advise indicating the runtime environment being used in the server's name. For example, in Eclipse, instead of letting the server name simply be "Apache Tomcat v7.0", make it "Apache Tomcat v7.0 - JRE 7". Of course, you should update this name if you change the runtime environment of this server later.
Source: http://www.codejava.net/ides/eclipse/how-to-change-java-runtime-environment-for-tomcat-in-eclipse
NOTE: This answer applies to any other IDE as well. You just need to make sure that your servlet container runs under JRE 7.

Scalable java web APP openshift - 503 error HAProxy

I started create a new java web application scalable, but is not working, since i got error
"503 Service Unavailable No server is available to handle this request".
Im using RESTful service
My code is:
TestClass
#Path("/test")
public class TestClass {
#GET
public String getName() {
return "John";
}
}
web.xml
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
metadata-complete="false">
<!-- Auto scan REST service -->
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
<listener>
<listener-class>
org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
</listener-class>
</listener>
<servlet>
<servlet-name>resteasy-servlet</servlet-name>
<servlet-class>
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>resteasy-servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
pom
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>myApp</groupId>
<artifactId>myApp</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>myApp</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>1.0.0.Final</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>2.3.1.GA</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>2.3.1.GA</version>
<scope>provided</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<!-- When built in OpenShift the 'openshift' profile will be used when
invoking mvn. -->
<!-- Use this profile for any OpenShift specific customization your app
will need. -->
<!-- By default that is to put the resulting archive into the 'deployments'
folder. -->
<!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
<id>openshift</id>
<build>
<finalName>myApp</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<outputDirectory>deployments</outputDirectory>
<warName>myApp</warName>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
In my Haproxy.cfg, i have this line option httpchk GET /myApp
Anyone can help?
If you do not have something in your application listening on the root context (/) then the haproxy will see your application as being down. You either need to have something listen on the root context, or change the monitoring option to point to a url that is returning a 200 (success) when it is polled.
Did you change the httpchk GET / to the httpchk GET /myApp?
Even if you change your application to be deployed at /myApp, you still need something that gives a 200 success on that url.

Categories

Resources