How to write Jersey Multipart webapp, Tomcat Server - java

I've been doing a lot of REST tutorials and enjoying them. Recently, I tried writing a jersey multipart webapp with Netbeans but I can't seem to because it seems something's missing my jersey library.
I downloaded the jersey-multipart.jar file, but still that didn't help:
#Path("/file")
public class UploadFileService {
#POST
#Path("/upload")
#Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(
#FormDataParam("file") InputStream uploadedInputStream,
#FormDataParam("file") FormDataContentDisposition fileDetail) {
This code is from blog. I'm trying to put it in my webapp, but the #FormDataParam tag and the FormDataContentDisposition class are not recognised. I downloaded the jersey-multipart.jar and that seemed to solve the #FormDataParam tag problem, but not the FormDataContentDisposition class.
I'm using Tomcat 7.0.
How do I go about successfully creating a jersey multipart webapp without any problems? And how come the jersey-multipart jar file isn't included in the jersey library in Netbeans?
Thanks.

Lutz Horn has a point, but for the sake of those using Netbeans 7.4 (Java EE 6) and are still struggling with this issue, here's a step by step on how to create your very own multipart rest web service and deploying on Tomcat, with Netbeans. (Note, deploying on Glassfish requires a slightly different configuration which isn't covered in this answer).
First off, my suggestion is to create a maven web application and not a normal web application. Reason is, the JAX-RS and Jersey libraries that come with Java EE 6 are not sufficient enough, and once you start fiddling around with external jars, things tend to get messy, especially with Jersey. (Hopefully, this has been corrected in Netbeans 8.0 (Java EE 7)).
(1) Create a maven web-app, choose Java EE 6 and Tomcat 7. Once you're done, you'll notice you don't have a web.xml. Most multipart tutorials will tell you to include certain configurations in your web.xml file. Don't bother with that. You don't need a web.xml file.
(2) Create a RESTfull web service by either writing it manually or using the wizard (right click on your maven web-app -- New -- Other -- Web Services -- [choose the RESTful web service you want])
(3) Open your pom.xml (you can find it under the Project Files folder in your maven web-app) and add these dependencies:
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.7</version>
</dependency>
If you're doing this for the first time, you need an active internet connection, as maven will download the dependencies from its central repository.
(4) Go to your ApplicationConfig class or whatever class that holds that contains your #ApplicationPath(). It should look like this:
#javax.ws.rs.ApplicationPath("webresources")
public class ApplicationConfig extends Application {
#Override
public Set<Class<?>> getClasses() {
Set<Class<?>> resources = new java.util.HashSet<Class<?>>();
resources.add(MultiPartFeature.class);
addRestResourceClasses(resources);
return resources;
}
/**
* Do not modify addRestResourceClasses() method.
* It is automatically populated with
* all resources defined in the project.
* If required, comment out calling this method in getClasses().
*/
private void addRestResourceClasses(Set<Class<?>> resources) {
resources.add(com.mycompany.mavenrestuploader.UploaderResource.class);
}
Note: resources.add(MultiPartFeature.class); That has to be included, otherwise Jersey multipart won't work.
The reason I put that line of code in the getClasses method and not the addRestResourceClasses method is because the addRestResourceClasses method gets modified whenever there's a change to your resource class, and if you include the MultiPartFeature code in there, it will get erased.
Once you've done all these things, you are good to go.
If you're just looking to create a RESTful web service without multipart, follow steps 1 to 3, but in step 3 do not include the jersey-media-multipart dependency.
I hope this helps you ;)

The imports for these two are
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
If you use Maven, add this dependencies:
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.0</version>
<type>jar</type>
</dependency>

Together with jersey-media-multipart dependency, instead of Application (see below) you can configure ResourceConfig:
#ApplicationPath("/")
public class AppConfig extends ResourceConfig {
public AppConfig() {
packages("packages.to.scan");
register(MultiPartFeature.class);
}
}
or Jersey REST configuration in web.xml:
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
</init-param>

Related

My IDE is not recognizing HTML commands for my servlet [duplicate]

This question already has answers here:
How do I import the javax.servlet / jakarta.servlet API in my Eclipse project?
(16 answers)
Closed 1 year ago.
I am learning how to create a servlet that takes HTML code and makes a program in my browser.
This code was supposed to output a simple welcome message in my browser via HTML. However, My eclipse IDE does not recognize any of the HTML commands in this code. It says that the imports are not accessible and that the HTTP variables can't be resolved to a type. I'm using tomcat version 10.0.12 and Java 13 for the code (I also have java 16 but eclipse only gave me the option to use 13). I've tried uninstalling and reinstalling Tomcat several times and adding servlet-api.jar but none of those changed a thing. I know there's an extra step I'm missing but I can't figure out what it is?
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import java.io.*;
public class WelcomeServlet extends HttpServlet {
#Override
protected void doGet( HttpServletRequest request,
HttpServletResponse response ) throws ServletException, IOException {
response.setContentType( "text/html" );
PrintWriter out = response.getWriter();
out.println( "<title>Welcome to Servlets!</title>" );
{...}
out.println( "</html>" );
out.close(); // close stream to complete the page
}
}
You've messed up your imports. It sounds like you're following a tutorial that's 20+ years old, a lot of what you're doing is extremely outdated. The web is a fairly fast moving environment; I strenously advise against using such old tutorials.
The correct import is import javax.servlet.http.HttpServletRequest;.
Some notes on what you're doing that are bad ideas:
Star imports aren't advised; it's a bit too easy to get confused about where things live or which type(s) you are fetching from where. Your IDE manages your imports for you; let it.
You don't want to write HTML inside strings inside your code. Use a templating engine such as Freemarker, Velocity, Thymeleaf, or Google Closure Templates. Alternatively, write static HTML with a ton of javascript (probably with a client-side javascript-based framework) and write your server as an API that doesn't 'answer' in terms of HTML files; it answers in terms of some structured data format such as JSON. Your static (as in, unchanging; any file-serving HTTP service can provide them) HTML+CSS+Javascript does the job of calling your API to get this structured data, and then your HTML+CSS+JavaScript does the job of rendering it into HTML.
Raw servlets is outdated; the API is extremely old and it shows, for example, you can't even use a simple for-each loop to iterate over all parameter names, because the API returns the obsolete Enumeration instead of the more modern Iterator or even Stream. You neither get the benefit of storing intermediate state in fields (because you aren't guaranteed one instance per invocation), but you also don't get to just dump it all in static fields either (as the spec doesn't guarantee that there'll only ever be one instance) - the worst of both worlds. Look into JAX-RS, Jersey, Dropwizard, sparkjava, or other such frameworks.
tl;dr
Your project lacks a JAR containing the definition of the Jakarta Servlet API (a set of interfaces).
Add jakarta.servlet-api as a dependency to your project, to present to your IDE the needed JAR file during development but omitted from your final build’s WAR file.
Details
Your import statements refer to the Jakarta Servlet API. That API is not built into Java. So you must make a Servlet API JAR file available to your IDE while developing.
Typically in Java development we use a tool such as Maven or Gradle to assist our IDE in obtaining external dependencies such as the Servlet API JAR.
If you are using Maven, edit your POM file to specify a dependency for the Servlet API JAR published as part of the Jakarta.ee project, by the Eclipse Foundation.
<!-- https://mvnrepository.com/artifact/jakarta.servlet/jakarta.servlet-api -->
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>5.0.0</version>
<scope>provided</scope>
</dependency>
Notice the scope element, with a value of provided. This means the JAR file should be downloaded, made available to your IDE while developing, but should not be copied into your resulting product when you build.
The output of your build will typically be a WAR file (not JAR). The provided scope means we do not want a copy of the Servlet API JAR within that WAR. The reason is that when developing Jakarta EE web apps, we expect to deploy to a compliant application server that carries its own copy of the Servlet API. Every “profile” of Jakarta EE compliant servers are required to include an implementation of the Servlet API.
So your POM will look something like this:
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>work.basil.example</groupId>
<artifactId>demo</artifactId>
<version>1.0-SNAPSHOT</version>
<name>demo</name>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/jakarta.servlet/jakarta.servlet-api -->
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>5.0.0</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.1</version>
<scope>test</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>
And here is the source code for a simple servlet.
package work.basil.example.demo;
import java.io.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
#WebServlet ( name = "helloServlet", value = "/hello-servlet" )
public class HelloServlet extends HttpServlet
{
private String message;
public void init ( )
{
message = "Hello World!";
}
public void doGet ( HttpServletRequest request , HttpServletResponse response ) throws IOException
{
response.setContentType( "text/html" );
// Hello
PrintWriter out = response.getWriter();
out.println( "<html><body>" );
out.println( "<h1>" + message + "</h1>" );
out.println( "</body></html>" );
}
public void destroy ( )
{
}
}
You said:
I've tried uninstalling and reinstalling Tomcat several times
Completely unrelated to your problem, I expect.
The installation of Tomcat comes with an implementation of the Servlet API. But your IDE does not “see” Tomcat during development. Your IDE needs to see the interfaces defined in the Servlet API.
Your IDE does not actually execute your servlet, so it does not need an implementation, it needs only the interfaces. When you run your Servlet from the IDE, Tomcat is invoked externally from the IDE. The IDE attaches a debugger connection to Tomcat to facilitate interactive debugging, but the IDE and Tomcat are actually running as separate distinct processes on the host OS. And as I said, Tomcat comes bundled with its own implementation of those interfaces, so your servlet is able to execute.
You said you are using Java 13. Be aware that Java 13 is no longer supported. You should move to either the latest version of Java (17, as of 2021-11), or to one of the Long-Term Support (LTS) versions (8, 11, 17).
If using Java 11 or 17 rather than 8, I would suggest using Tomcat 10.1.x rather than Tomcat 10.0.x. Tomcat 10.1.x supports Jakarta EE 9.1 and 10, which supports Java 11 and later versus Java 8.
See the Tomcat version comparison page.

RESTEasy annotation scan unable to find resources (under Tomcat)

I'm trying to update WAR with old RESTEasy 3.0.5 to something newer. 3.0.6 works fine, but after updating to 3.0.7 (or higher, like 3.0.24) all resources (#Path) are lost — 404 for any resource. WAR is run under Apache Tomcat server.
I believe the reason is linked to change of annotation scanner:
https://issues.jboss.org/browse/RESTEASY-1010
I've tried to create class which extends javax.ws.rs.core.Application instead of web.xml configuration. According to answer https://stackoverflow.com/a/29957040/2528366, empty set should trigger scan for #Path but no any resource is found. If I override getClasses() which returns non-empty set, that resources work as expected.
web.xml: https://pastebin.com/uRD2w6Z6
New Application inherited class:
#ApplicationPath("/rest")
public class WebApi extends Application
{
#Override
public Set<Class<?>> getClasses()
{
Set<Class<?>> s = new HashSet<>();
// if line below is uncommented SomeResource works fine
// s.add(SomeResourceImpl.class);
return s;
}
}
Resources are interfaces and implementation is in derived classes. Moving annotations to classes itself changes nothing.
What's wrong with annotations or configuration? Or is there something else needed to trigger scanning for annotations?
If you are using a Tomcat version that is compatible with the Servlet 3.0 specification, you need to add the resteasy-servlet-initializer dependency :
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-servlet-initializer</artifactId>
<version>${resteasy.version}</version>
</dependency>
As stated in the documentation :
Resteasy uses the ServletContainerInitializer integration interface in Servlet 3.0 containers to initialize an application, automatically scanning for resources and providers. To enable automatic scanning, you must also include the resteasy-servlet-initializer artifact in your WAR file as well

Swagger UI displays Error still after using validatorUrl as null

Though the scenario, if I was to describe, is similar to
Swagger UI Displays but I get an "ERROR" indicator. Everything works fine for me, my routes are listed properly, but the Error is displayed and the solution suggested on all such similar threads is pertaining to setting validationUrl=null.
I am using the following dependencies -
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>io.federecio</groupId>
<artifactId>dropwizard-swagger</artifactId>
<version>0.7.0</version>
</dependency>
This is what my register code looks like -
#Override
public void initialize(Bootstrap<CustomServiceConfig> bootstrap) {
bootstrap.addBundle(new SwaggerBundle<CustomServiceConfig>() {
#Override
protected SwaggerBundleConfiguration getSwaggerBundleConfiguration(
CustomServiceConfig customServiceConfig) {
return customServiceConfig.getSwaggerBundleConfiguration();
}
});
}
where these configuration in the config.yml are -
swagger:
title: Custom Service
description: APIs for Test
contact: me#alias.com
uriPrefix: /
resourcePackage: com.x.y.package
I've tried updating the SwaggerBundleConfiguration in the above .yml to add
validatorUrl=null
But this doesn't seem to be fixing the issue either. How can this be solved?
Inserting validatorURL: null into the constructor for the swagger ui has to happen in the swagger index.html file, not the Dropwizard yaml configuration file [see the SO post you referenced].
So you have a couple options, but to start I wouldn't recommend the dropwizard-swagger package because it seems to have fallen rather far behind Dropwizard itself. According to the version documentation on its page, it only supports up to Dropwizard 0.8 and swagger-ui 2.4. Dropwizard is at 1.x and the swagger-ui 3.x.
Option 1
If you do away with the dropwizard-swagger lib you can put the swagger-ui assets directly into your project under resources directory and add an AssetBundle to your Dropwizard application. This bundle allows serving of static content on your classpath. The static html you'll need is all in the dist folder here (i.e. copy it to /resources in your dropwizard project).
You'd have something like
#Override
public void initialize(Bootstrap<CustomServiceConfig> bootstrap) {
bootstrap.addBundle(new AssetsBundle("/assets/swagger", "/swagger", "index.html"));
}
which will serve the swagger UI on localhost:<port>/swagger like the dropwizard-swagger lib does.
For this solution to work, you'll need to generate the swagger json file as well and put that into the correct path in your build directory (resources path too). The swagger-maven-plugin can help do this for you. Here is a link to some discussion around how to bundle the static swagger ui and swagger json in your app. You'll need to modify the index.html to point at your swagger json file. The line of code is here.
const ui = SwaggerUIBundle({
url: "/path/relative/to/your/java/jar/swagger-api.json",
validatorUrl: null,
...
}
Option 2
You can fork the dropwizard-swagger code, modify the index.html file that is include to have validatorUrl: null set. The place you need to add this is in the constructor for the SwaggerUI js object. You can see it here.
In brief:
window.swaggerUi = new SwaggerUi({
url: url,
validatorUrl: null,
...
}
You'll then need to rebuild the library and include in your project this modified version of dropwizard-swagger library. Note that the dropwizard-swagger project just happens to create an AssetBundle for you.
Summary
Either way you'll need to modify the index.html file that is part of the swagger ui distribution. The easiest way forward may be to just ignore the error icon for now.

Spring MVC with Boot: "There was an unexpected error (type=Not Found, status=404)"

So I'm new to Spring and I've so far gotten a simple web API running connected to a MongoDB database, but I'm having trouble generating just plain old views using .jsp or .html files. I've tried a variety of different approaches: InternalResourceViewResolver, XmlViewResolver, returning Strings instead of ModelAndView objects, nothing seems to be working for me. I have the following code:
Edit: here is a git repo with my project: https://github.com/jwallp/Spring-Test
As the above project is, I am getting a white label error upon going to /index which says:
There was an unexpected error (type=Internal Server Error, status=500).
Circular view path [index]: would dispatch back to the current handler URL [/index] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)
Edit: So I managed to get the view to finally load by using spring.view.prefix and spring.view.suffix instead of spring.mvc.view.prefix and such, and by moving my WEB-INF directory from my project root to inside <project root>/src/main/webapp/. I just wanted to know, if my WEB-INF directory is contained within another directory, will it still function as intended (making its contents not directly visible)?
Spring Boot has limited support for JSP, because of its use of an embedded servlet container. From the Spring Boot reference documentation:
When running a Spring Boot application that uses an embedded servlet
container (and is packaged as an executable archive), there are some
limitations in the JSP support.
With Tomcat it should work if you use war packaging, i.e. an
executable war will work, and will also be deployable to a standard
container (not limited to, but including Tomcat). An executable jar
will not work because of a hard coded file pattern in Tomcat. Jetty
does not currently work as an embedded container with JSPs.
Here is a basic example of using jsp in spring boot application.
Hope you have the JSP libraries in your classpath. If you are using maven, including the following dependencies in pom.xml will have those:
<!-- For using JSP -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- If you want to use JSTL -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
Also, you may need to put this line at the top of the JSP file:
<%# page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
Update
Doing the following changes to your project at GitHub worked in my environment:
Move the WEB-INF folder into src/main/webapp. That's the place for it.
In application.properties replace
spring.mvc.view.prefix=/WEB-INF/pages/
spring.mvc.view.suffix=.jsp
with
spring.view.prefix: /WEB-INF/pages/
spring.view.suffix: .jsp
Seems the former will work with Spring Boot 1.3, but not not with the current stable release.
Try the Following:
package hello;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
public class IndexController
{
#RequestMapping("/")
public String index()
{
return "index";
}
}
We ran into this problem at work while upgrading an older application to Spring Boot. What we did:
The prefix and suffix mappings as given above for application.properties (though our prefix was just /WEB-INF/).
Moved our CSS, JavaScript, HTML files to a resources\static folder. We had subdirectories under that for each type.
Places where window.open("somefile.jsp") was used, was changed to window.open("somevalue.do") where somevalue mapped to a #RequestMapping value and the setViewName for the ModelAndView of that method mapped to the previous jsp. Where there was a window.open("somefile.html") we changed it to map to window.open("includes/somefile.html") where includes is a subdirectory in our resources/static tree.
I ran into this problem few times. It was because I put /WEB-INF/ in /src/main/java folder. Latest I created separate path for the INF file in /src/main/webapp and I was able to run my application correctly and displayed the text in the browser.
Following jsp files relocation can solve the problem. I solved my problem this way:
Move the .jsp files to:
"src/main/resources/META-INF/resources/WEB-INF/jsp".
Make sure the application.properties file contains:
spring.view.prefix: /WEB-INF/jsp/
spring.view.suffix: .jsp
Your controller class should be like:
#Controller
public class IndexController
{
#RequestMapping("/")
public String index()
{
return "index";
}
}
If you are using maven, include the following dependencies in pom.xml
<!-- For using JSP -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- If you want to use JSTL -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
It should then work.
I added one line to my application.properties file.
server.tomcat.additional-tld-skip-patterns=hk2-utils.jar,javax.annotation-api.jar,javax.inject.jar,hk2-api.jar,config-types.jar,hk2-core.jar,hk2-config.jar,tiger-types.jar,validation-api.jar,jboss-logging.jar,classmate.jar,hk2-locator.jar,javassist.jar,hk2-runlevel.jar,class-model.jar,asm-all-repackaged.jar
It should then run.
I have used mvn spring-boot:run
It's worked for me
Eventhough I have tried many ways to fix this issue, couldn't find perfect solution.
If you are using Intellij IDEA : do not try to run Spring Boot application(with dynamic .jsp views) with the IDE's run ▶︎ button.
$ cd {PROJECT_FOLDER}
$ ls //Make sure that you are in the same folder where pom.xml resides
and then run below command
$ mvn spring-boot:run
Now your application should be served at localhost:8080.
i have faced the same problem and my solution was replacing the
spring.view.prefix: /WEB-INF/pages/
spring.view.suffix: .jsp
with a configuration class like this. it worked for me!
package com.rbc.sample.user.login.sample;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.UrlBasedViewResolver;
#Configuration
public class WebConfig {
public static final String RESOLVER_PREFIX= "/WEB_INF/jsp/";
public static final String RESOLVER_SUFIX=".jsp";
#Bean
public ViewResolver viewResolver(){
UrlBasedViewResolver viewResolver=new InternalResourceViewResolver();
viewResolver.setPrefix(RESOLVER_PREFIX);
viewResolver.setSuffix(RESOLVER_SUFIX);
return viewResolver;
}
}

Issues Converting Mule Tomcat WAR to Spring Boot

I've been going through the process of converting my Mule project to a Spring Boot application, and have hit a snag I can't seem to figure out.
I'm pretty new to Spring Boot so I'm not sure if my issues lie with it, or with the way I'm doing my mule stuff.
Here is my sample project I've been trying to convert: https://github.com/JustinBell/mule-webapp-example
When I deploy this to a tomcat instance it works great, the issue comes when I try to run it as a Spring Boot application I'm getting this exception:
ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
Just as a note I'm moving from mule 3.6.1 to 3.7.0-M1 as that's required (from my understanding) to use Spring Boot.
I've tried looking around for support on this issue which seems to pretty common, but none of the suggestions I've found have solved the issue.
Thanks for any help with these issues!
There are a few things that aren't quite right in your code as it stands.
If you want to build a web app with Spring Boot, you'll typically want to add a dependency on spring-boot-starter-web. This provides, among other things, the embedded servlet container:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
</dependency>
Your app's dependency on org.mule.transports:mule-transport-servlet pulls in a very old version of Tomcat's Coyote module. You need to exclude this to avoid it clashing with the up-to-date dependency that's provided by spring-boot-starter-web:
<dependency>
<groupId>org.mule.transports</groupId>
<artifactId>mule-transport-servlet</artifactId>
<version>${mule.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat</groupId>
<artifactId>coyote</artifactId>
</exclusion>
</exclusions>
</dependency>
Your Application class is trying to run MuleContextInitializer which it also declares as a bean. It should be running Application.class:
#SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class);
}
// ...
}
Your Application class is also in the default package. You should avoid using the default package as it will cause Spring Boot to scan then entire classpath looking for your application's classes and configuration. Moving it into a package of its own to stop this from happening.
Lastly, the app fails to launch as it's looking for a file named mule-config.xml. Renaming mule-webapp-demo.xml to mule-config.xml addresses this.
I believe autodelete is an Enterprise feature, perhaps you are using ftp rather than ftp-ee.

Categories