I am new to swagger, I am trying to swagger to my tomcat application, and below is my WEb.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>Restful Web Application</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:xxx/xxx/xxx/xml/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>jersey-helloworld-serlvet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>xxx.xxx.xxx.resource</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>JerseyJaxrsConfig</servlet-name>
<servlet-class>com.wordnik.swagger.jersey.config.JerseyJaxrsConfig</servlet-class>
<init-param>
<param-name>api.version</param-name>
<param-value>1.0.0</param-value>
</init-param>
<init-param>
<param-name>swagger.api.basepath</param-name>
<param-value>http://localhost:8088/sms</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-helloworld-serlvet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
And I added Swagger Ui to my WebContent/WEB-INF folder, and added
swagger-annotations_2.9.1
swagger-jersey-jaxrs_2.10
swagger-core_2.10 jars to my class path
I am getting the below error:
java.lang.NoClassDefFoundError: com/wordnik/swagger/config/ConfigFactory
Appreciate your help on this.
Related
Receiving this error from console:
*org.springframework.beans.factory.BeanDefinitionStoreException:
IOException parsing XML document from ServletContext resource
[/WEB- INF/spring-dispatcher-servlet.xml]; nested exception is
java.io.FileNotFoundException: Could not open ServletContext resource
[/WEB-INF/spring-dispatcher-servlet.xml]*
That's the error I receive from:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>fj21-tarefas</display-name>
<welcome-file-list>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
I doing
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-context.xml</param-value>
</init-param>
to change the default context from springmvc, but it is not working. Already took some advice here to write a servlet-name tag to the file name-context.xml convention, same error.
You should try changing the servlet name. Expected Spring web-context metadata XML file name should servletname-servlet.xml, this was expected filename till Spring 4, not sure if it is changed in spring 5.
. As your servlet name is springmvc, filename should be springmvc-servlet.xml.
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springmvc-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/app-name/*</url-pattern>
</servlet-mapping>
Make your web.xml look like this, taken straight from the Spring documentation:
<web-app>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-context.xml</param-value>
</context-param>
<servlet>
<servlet-name>app</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>app</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
I want to declare tow packages in the web.xml in a REST application using jax-rs.
this my code of web.xml for the first package
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>LampPostZ12</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>lamppost12</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>cuLampPost</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>lamppost12</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
like that, everything is working well.
but when I add the declaration of the second package:
<servlet>
<servlet-name>lamppost12</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>cuLampPost</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>lamppost12</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>radar12</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>radar</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>radar12</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
it appears as it:
Etat HTTP 404
thank's in advance
The problem is solved when I declare in the web.xml, like this:
<servlet>
<servlet-name>lamppost12</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>cuLampPost;radar</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>lamppost12</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
The following error is shown when trying to deploy WAR in JBoss 6.1.0
DEPLOYMENTS IN ERROR:
Deployment
"vfs:///D:/workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_AS_6.x1555321418499/deploy/MyProject.war" is in error due to the following reason(s):
org.jboss.xb.binding.JBossXBRuntimeException: filter cannot appear in this position. Expected content of web-app is unordered_sequence: error-page* welcome-file-list? servlet-mapping* login-config? mime-mapping* distributable? session-config? security-role* taglib* security-constraint* context-param* servlet* {all descriptionGroup}? {unordered_sequence jndiEnvironmentRefsGroup}?
The following is the web.xml file
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>false</param-value>
</context-param>
<filter>
<filter-name>AuthenticationFilter</filter-name>
<filter-class>mypackage.restauthentication.RestAuthenticationFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>AuthenticationFilter</filter-name>
<url-pattern>/services/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>mypackage.restauthentication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>REST Service</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
</web-app>
According to the error message, the <filter> is placed incorrectly in web.xml. Expected content of web-app is unordered_sequence: error-page* welcome-file-list? servlet-mapping* login-config? mime-mapping* distributable? session-config? security-role* taglib* security-constraint* context-param* servlet* {all descriptionGroup}? {unordered_sequence jndiEnvironmentRefsGroup}?
What is the correct order to place the same? This is a web archive which deploys Jersey REST web services with basic authentication.
Try This ..
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>false</param-value>
</context-param>
<servlet>
<servlet-name>REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>mypackage.restauthentication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>REST Service</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>AuthenticationFilter</filter-name>
<filter-class>mypackage.restauthentication.RestAuthenticationFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>AuthenticationFilter</filter-name>
<url-pattern>/services/*</url-pattern>
</filter-mapping>
</web-app>
I am trying to add rest api within my application so i added two servlet one for handling JSF request another for Rest API request.
web.xml
<?xml version="1.0"?>
<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"
>
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
<param-value>-1</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>redmond</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>
com.sun.jersey.spi.container.servlet.ServletContainer
</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.infinite.npsc.webapi</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
<param-value>com.infinite.npsc.webapi.CorsFilter</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
</web-app>
so, for example i want to call api as
http://localhost:5081/ApplicationFormFillingProcess-portlet/api/savePayment/2075-531345
but now i get an error of com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
if i changed jersey servlet url mapping from
<url-pattern>/api/*</url-pattern>
to
<url-pattern>/*</url-pattern>
i can call the api. but my images and other static contents are not loaded.
I am migrating from com.sun.jersey 1.x to org.glassfish.jersey 2.x,
my web.xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<!-- Bean Configuration -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:application-context.xml</param-value>
</context-param>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>webservices</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<servlet>
<servlet-name>jersey-servlet</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.jersey.series.spring.security.service</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.xyz.webservices</param-value>
</init-param>
<!-- Enable / Disable Jersey Tracing and Logging. -->
<init-param>
<param-name>jersey.config.server.tracing</param-name>
<param-value>${jersey.enable.trace}</param-value>
</init-param>
<init-param>
<param-name>jersey.disable.wadl</param-name>
<param-value>${jersey.disable.wadl}</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
So the resources defined under com.xyz.webservices.resources, whenever are called like '/app/api/data' says 404 page not found. Am i doing something wrong here?
I got the code working by modifying my web.xml as:
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.jersey.series.spring.security.service,com.xyz.webservices</param-value>
</init-param>
<!-- Enable / Disable Jersey Tracing -->
<init-param>
<param-name>jersey.config.server.tracing</param-name>
<param-value>${jersey.enable.trace}</param-value>
</init-param>
<init-param>
<param-name>jersey.disable.wadl</param-name>
<param-value>${jersey.disable.wadl}</param-value>
</init-param>
<!-- Enabling Jackson Feature and Logging -->
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>org.glassfish.jersey.jackson.JacksonFeature,org.glassfish.jersey.filter.LoggingFilter,org.glassfish.jersey.server.filter.EncodingFilter,org.glassfish.jersey.message.DeflateEncoder,org.glassfish.jersey.message.GZipEncoder</param-value>
</init-param>