Spring boot war not working on EAP 6 - java

I have created a small REST-based application using spring boot. The application is deployed on EAP 6(JBoss) as a war package.
As EAP 6 is based on Java 1.7 I have configured that in my maven pom to compile and use Java 1.7 version.
When I am deploying the application I can see in the server logs that the controller is getting registered but when I am hitting it I am getting 404. Also I JBoss is not picking up my context root configuration but taking the application name as the context root. I am tested all the possible endpoints but everything is giving 404.
Can someone suggest me something which can help me to proceed forward?
POM file:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.7</java.version>
</properties>
....
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Application configuration
package com.org.orderhistory.v2.orderhistory.v2;
import ...
#SpringBootApplication
public class Application extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
package com.org.orderhistory.v2.orderhistory.v2.controllers;
import ...
#RestController
#RequestMapping(value="/myorder/weborders")
public class WebOrderControllers {
#RequestMapping(value="/{webUserId}",method = RequestMethod.GET, produces = "application/json")
public List<WebOrder> getWebOrdersForUser(#PathVariable Long webUserId) {
JBoss Logs
2017-10-09 02:24:29,744 [ServerService Thread Pool -- 594] INFO [org.springframework.boot.web.servlet.FilterRegistrationBean] Mapping filter: 'requestContextFilter' to: [/*]
2017-10-09 02:24:30,368 [ServerService Thread Pool -- 594] INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter] Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#5a46b924: startup date [Mon Oct 09 02:24:27 EDT 2017]; root of context hierarchy
2017-10-09 02:24:30,451 [ServerService Thread Pool -- 594] INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] Mapped "{[/org/weborders/{webUserId}],methods=[GET],produces=[application/json]}" onto public java.util.List<com.org.www.order.model.WebOrder> com.org.orderhistory.v2.orderhistory.v2.controllers.WebOrderControllers.getWebOrdersForUser(java.lang.Long)

Exact same issue here. Try this:
1. In pom.xml:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
2. Add a class implements WebApplicationInitializer:
#Configuration
public class WebApplicationInitializerImpl implements WebApplicationInitializer{
#Override
public void onStartup(ServletContext container) throws ServletException {
WebApplicationContext context = getContext();
Dynamic registration = container.addServlet("dispatcher", new DispatcherServlet(context));
registration.setLoadOnStartup(1);
registration.addMapping("/*");
}
private WebApplicationContext getContext() {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setConfigLocation(ApplicationMain.class.getName());
return context;
}
}
3. Remember to extend SpringBootServletInitializer by your application:
#SpringBootApplication
public class ApplicationMain extends SpringBootServletInitializer{
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(ApplicationMain.class);
}
public static void main(String[] args) {
SpringApplication.run(ApplicationMain.class, args);
}
}
If it works, then the problem is related to dispatcherServlet.
When using Spring boot, a dispatcherServlet should have been configured automatically. (That is a part of auto Configuration)
And this situation seems to be the issue of jboss, according to Redhat's explanation:
Because JBoss enforces the servlet specification's requirements about not registering conflicting mappings even for it's own server-added DefaultServlet.
To check if your dispatcherServlet is registered as expected, try this:
[standalone#localhost:9999 /] /deployment=spring-boot-application.war/subsystem=web:read-resource(recursive=true)
Not working:
{
"outcome" => "success",
"result" => {
"context-root" => "/spring-boot-application",
"servlet" => undefined,
"virtual-host" => "default-host"
}
}
Working:
{
"outcome" => "success",
"result" => {
"context-root" => "/spring-boot-application",
"virtual-host" => "default-host",
"servlet" => {"appServlet" => {
"servlet-class" => "org.springframework.web.servlet.DispatcherServlet",
"servlet-name" => "appServlet"
}}
}
}
Hope it solves your problem.
Reference:
https://access.redhat.com/solutions/1211203
https://blog.csdn.net/u011160656/article/details/78809239

Related

Spring Boot Controller not mapping (Whitelabel Error Page)

I have a Spring REST project that is redirecting all requests to error page, even if they are mapped in the controller.
I reduced the code to the smallest possible version that produces the error:
Here is the project structure:
Here is the Application class (The imports are removed to make the thread easier to read):
package com.example.demo;
#Controller
#SpringBootApplication
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
#GetMapping("/greeting")
#ResponseBody
public String greeting() {
return "greeting";
}
}
Originally I hade a sperate controller from the App class, but moved the controller code to the app class to make sure that this is not a project structure problem
Here is the controller code (Tried with and without it, and received the same error):
#Controller
#SpringBootApplication
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
#GetMapping("/hello")
#ResponseBody
public String greeting() {
return "greeting";
}
}
(Both http://localhost:8080/greeting as well as well http://localhost:8080/hello return the same error page)
Dependencies and plugins from the pom file:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
(Tried with and without tomcat as dependency and nothing changed)
And lastly here is the error message I receive in the browser when I visit the links (http://localhost:8080/greeting and http://localhost:8080/hello):
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sun Nov 27 00:16:08 CET 2022
There was an unexpected error (type=Not Found, status=404).
Edit:
After setting debug to true in project.properties, here is the error message I see in console (Worth mentioning that the project ran with no issues when I tried it on another system (Same OS)):
GET "/greeting", parameters={}
Mapped to ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]
Resource not found
Completed 404 NOT_FOUND
"ERROR" dispatch for GET "/error", parameters={}
(Timestamps are removed to make reading easier)
Did you tried making call to the endpoint via postman ? If so, can you try again after removing #ResponseBody annotation.
Instead of #Controller use #RestController

Spring boot MVC: RequestMapping isn't recognized in Spring boot 2.1.4

Can someone answer this silly question - How to configure Thymeleaf in Spring boot release 2.1.4?
I have declared the right dependencies:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
Also the config:
#SpringBootApplication
#ComponentScan("org.mystuff.myproj")
#EnableAutoConfiguration
public class Init extends SpringBootServletInitializer{
And the controller looks regular:
#Controller
#RequestMapping("/a")
public class IndexController {
private static final Logger logger = LoggerFactory.getLogger(IndexController.class);
#PostConstruct
private void test() {
logger.info("********************************************************************");
}
#RequestMapping("/")
private String index() {
return "index2";
}
I do see that the #Controller bean gets initiated (the "*****..."), but when I try to locate in the logs the "mapped" or atleast something related, the only thing I find is:
2019-04-23 15:55:15 WARN [localhost-startStop-1] JpaBaseConfiguration$JpaWebConfiguration$JpaWebMvcConfiguration.openEntityManagerInViewInterceptor: spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2019-04-23 15:55:16 INFO [localhost-startStop-1] WelcomePageHandlerMapping.<init>: Adding welcome page: ServletContext resource [/index.html]
And I'm failing to find an answer to the "What has changed" question.
After a while I realized that Spring Boot 2.1.4 requires TomCat 9, while I was using 8.5.
After this I started to get progress, but still the Thymeleaf isn't working, and if /templates has a index.html, the default Resolver is used, which ignores Thymeleaf's "fragments" and stuff (loads like a regular html page).

Spring Boot | localhost: 8080 404 error page displayed

I created a Spring Boot Maven project, however my RequestMapping, as well as localhost:8080 return a 404 error page. I think the issue is with how my packages are setup, but I've tried solutions in multiple questions, and I still cant get around the error page. Could you guys point me in the right direction as to how to resolve this issue? Perhaps I need to add the Component annotation above my Main class? But I've tried this solution, and the error still persists.
Here is my package structure:
/src/main/java
ControllerLayer
UsersController.java
DataAccessLayer
UsersDAL.java
ServiceLayer
UsersService.java
Main
Main.java
Main.java:
#SpringBootApplication(scanBasePackages = {
"/src/main/java/ControllerLayer", "/src/main/java/DataAccessLayer",
"/src/main/java/ServiceLayer" })
public class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
}
UsersController.java:
import Entities.Users;
import ServiceLayer.UsersService;
#RestController
#RequestMapping("/users")
public class UsersController {
#Autowired
private UsersService usersService;
#RequestMapping(value =
"/create/{userId}/{userPassword}/{userAge}/{userEmail}"
+ "/{userFirstName}/{userlastName}", method =
RequestMethod.POST)
public void createUser(#PathVariable("userId")String userId,
#PathVariable("userPassword")String userPassword,
#PathVariable("userAge")int userAge,
#PathVariable("userEmail")String userEmail,
#PathVariable("userFirstName")String userFirstName,
#PathVariable("userLastName")String userLastName) {
usersService.createUser(new Users(userId, userPassword,
userAge, userEmail, userFirstName, userLastName));
}
}
UserService.java
import DataAccessLayer.UsersDAL;
import Entities.Users;
#Service
public class UsersService {
#Autowired
private UsersDAL usersDAL;
public void createUser(Users user) {
usersDAL.createUser(user);
}
}
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xProjectAlpha</groupId>
<artifactId>org.htech.xProjectAlpha</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.9.Final</version><!--$NO-MVN-MAN-VER$-->
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
When a request is sent, then a response shall be returned. In your case, you didn't send any content with the response and that's why you get 404 error (page not found).
In main.java, try:
#SpringBootApplication(scanBasePackages = {
"ControllerLayer", "DataAccessLayer",
"ServiceLayer" })
Your package names shouldn't include the root path in the project.
It is advisable to have spring boot Application class in root package and have all other classes in package structure below that package .You don't have to worry about component scan as an example
package com.igt.customer;
import java.util.Arrays;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
#SpringBootApplication
public class CustomerApplication {
public static void main(String[] args) {
SpringApplication.run(CustomerApplication.class, args);
}
#Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
};
}
}
Controller class
package com.igt.customer.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
#RestController
public class EmployeeController {
#RequestMapping("/employee")
public String employee() {
return "Greetings from Sam!";
}
}
running the application (go to the directory of your application on cmd )
E:\MongoDb\New folder\customer>mvn install -U -e
you should see this in the end if its fine
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.686 s
[INFO] Finished at: 2017-08-16T16:39:57+05:30
[INFO] Final Memory: 21M/219M
[INFO] ------------------------------------------------------------------------
run the jar file
E:\MongoDb\New folder\customer\target>java -jar customer-0.0.1-SNAPSHOT.jar
accessing the application
http://localhost:8080/employee
Notice application name is not required in URL
P.S i have written extra detail here as i have experienced if you are new to spring boot building and running the application is a challenge , in my application i had created a rest controller in the same package as the Application class with RequestMapping "/" as i was getting 404 error , Please see the link below as a reference
spring boot application
This issue will be simply solved if you remove the main package of the main.java class.
The new structure will be:
/src/main/java
Main.java
ControllerLayer
UsersController.java
DataAccessLayer
UsersDAL.java
ServiceLayer
UsersService.java
In my Spring boot application, there is no need to scan the base packages manually because all the configurations are embedded in a single annotation #SpringBootApplication. Please refer to this link.
I don't understand how the base packages are initially configured. Can someone please explain this?
For example, if your base package looks like:
com.example.myapp.SpringApplication
... it means your application takes base packages as com.example.myapp. So if you can create all Controllers, Service, Repository under com.example.myapp in the sense it will load your Controllers, Service, Repository easily or else it can't able to load. This is because springbootapplication intially sets the base packages and loads whatever java classes are inside the base package. So because of this you get a 404 error in the browser as well as in postman. So try to match with base package.

Spring Boot Starter-Web tries to connect to Mongo at startup

I am experiencing some problems using Spring Boot and MongoDB external driver. I can't use the project Spring Data MongoDB, because I need to use the ufficial async driver given by Mongo. However, I need to use Spring Boot, because the module I am developing is part of a bigger project using this library.
Here is my pom.xml file.
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>tx-view</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- omissis -->
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-async</artifactId>
<version>${mongodb.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
In detail, I am using Spring Boot 1.4.1 and Mongo Async Driver 3.2.2.
Here is my application.
#SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
public class TxViewApplication {
public static void main(String[] args) {
SpringApplication.run(TxViewApplication.class, args);
}
#Value("${mongo.uri}")
private String mongoUri;
#Bean
public MongoClient mongoClient() {
return MongoClients.create(mongoUri);
}
}
It follows the only (empty) test I have at the moment.
#SpringBootTest
#RunWith(SpringRunner.class)
public class ApplicationTest {
#Test
public void loadContext() throws Exception {}
}
I have no other code in this project. When I run the test, I have the following error:
2016-11-22 15:43:58.597 INFO 4572 --- [null'}-db:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server db:27017
com.mongodb.MongoException: java.io.IOException: Il computer remoto ha rifiutato la connessione di rete.
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:125) ~[mongodb-driver-core-3.2.2.jar:na]
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:128) ~[mongodb-driver-core-3.2.2.jar:na]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_101]
Caused by: java.io.IOException: Il computer remoto ha rifiutato la connessione di rete.
at sun.nio.ch.Iocp.translateErrorToIOException(Iocp.java:309) ~[na:1.8.0_101]
at sun.nio.ch.Iocp.access$700(Iocp.java:46) ~[na:1.8.0_101]
at sun.nio.ch.Iocp$EventHandlerTask.run(Iocp.java:399) ~[na:1.8.0_101]
at sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112) ~[na:1.8.0_101]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_101]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_101]
... 1 common frames omitted
As you can see, I have properly inserted the exclude clause in the SpringBootApplication annotation in order to stop Spring Boot to try handle its own the connection to Mongo, as suggested in Mongo tries to connect automatically to port 27017(localhost).
I have also noticed that I started to have the error after the addition to the pom.xml of the dependency to spring-boot-starter-web.
How can I inhibit Spring Boot to try to connect automatically to Mongo at startup? The same problem is present with the synchronous version of MongoDB driver.
--- EDIT ---
I have also try to build a wrapper around the async.MongoClient object, in this way:
public class MongoWrapper {
private final MongoClient mongo;
public MongoWrapper() {
mongo = MongoClients.create();
}
public MongoClient getMongo() {
return mongo;
}
}
The configuration was changed accordingly.
#Bean
public MongoWrapper mongo() {
return new MongoWrapper();
}
Unfortunately, nothing had changed. Spring Boot seems to intercept the MongoClient object also in this way :(
Thanks a lot.
You have a MongoClient bean in your own configuration which does not make any sense to me if you've excluded the auto-configuration.
I've commented out the #Bean definition in your own config and no attempt to connect to Mongo is performed now. I am not sure I answer to your question and you're probably looking for something else but if you don't want to use mongo, don't define a MongoClient in your own config!
This helped us to disable async java driver of MongoDB to use default configuration:
#EnableAutoConfiguration(exclude = {MongoReactiveAutoConfiguration.class})

Embedded tomcat fails to start when upgraded from Spring Boot 1.3.3 -> 1.3.5

Spring Boot application fails to launch after upgrade from 1.3.3 to 1.3.5.
Spring is unable to start embedded container (Tomcat 8) and following error message is displayed:
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embeddedServletContainerFactory': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [wad.config.HttpsConfiguration$1]: No default constructor found; nested exception is java.lang.NoSuchMethodException: wad.config.HttpsConfiguration$1.()
Basically this error message says it can't create the embeddedServletContainerFactory, but it's not clear to me what [wad.config.HttpsConfiguration$1] refers to. The Java configuration class itself is in package wad.config and named HttpsConfiguration.
I tried to add empty constructor to my HttpsConfiguration.java but it didn't help.
Here are the relevant parts of my POM:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
...
</dependencies>
My Application class:
#EntityScan(
basePackageClasses = {Application.class, Jsr310JpaConverters.class}
)
#SpringBootApplication
#Import({DevProfile.class})
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
And here is my configuration for port redirect from 8080 -> 8443 (configurable via application.properties):
#Configuration
public class HttpsConfiguration {
#Value("${server.port}")
private int httpsPort;
#Value("${server.port.http}")
private int httpPort;
#Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
#Override
protected void postProcessContext(Context context) {
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/*");
securityConstraint.addCollection(collection);
context.addConstraint(securityConstraint);
}
};
tomcat.addAdditionalTomcatConnectors(initiateHttpConnector());
return tomcat;
}
// redirect from (http) port to (https) if https is enabled.
private Connector initiateHttpConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
connector.setPort(httpPort);
connector.setSecure(false);
connector.setRedirectPort(httpsPort);
return connector;
}
application.properties config:
...
#Actuator port
management.port = 9001
#HTTPS port
server.port=8443
#HTTP port
server.port.http=8080
#Enable SSL
server.ssl.enabled=true
...
Update:
Issue can be reproduced with Spring Boot 1.3.5 project configured with the above POM, application.properties and HttpSecurity & Application classes.
The usage of spring-boot-starter-actuator dependency together with management.port
being defined in application.properties causes starting the embedded tomcat container to fail.
Removing the management.port property definition from application.properties makes the application to start up again.
It is worth noting that while removing the property fixed the issue it's not clear why.
The solution this problem can be found here:
https://github.com/spring-projects/spring-boot/issues/6193
and creating a separate class extending TomcatEmbeddedServletContainerFactory and in that class have a public constructor that class super. The class extending TomcatEmbeddedServletContainerFactory can't be an inner class, it must be in it's own file and public in the package, otherwise the error will not go away.

Categories

Resources