I have two files in my application.
The Main class file.
package in.njari.util;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class UtilApplication {
public static void main(String[] args) {
SpringApplication.run(UtilApplication.class, args);
}
}
The controller class.
package in.njari.util.controller;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
#RestController
public class UtilController {
#GetMapping("/util")
public ResponseEntity<?> f(){
return new ResponseEntity<>("I provide insights.", HttpStatus.OK);
}
}
My application.properties looks like :
server.servlet.context-path=/util-service
logging.level.org.springframework.core.io.support=DEBUG
logging.level.org.springframework.context.annotation=DEBUG
Here's what my console looks like :
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.5.RELEASE)
2022-04-06 11:19:53.819 INFO 57700 --- [ main] in.njari.util.UtilApplication : Starting UtilApplication on njari-MacBook-Pro.local with PID 57700 (/Users/rajdeep/X/util/target/classes started by rajdeep in /Users/rajdeep/X/util)
2022-04-06 11:19:53.821 INFO 57700 --- [ main] in.njari.util.UtilApplication : No active profile set, falling back to default profiles: default
2022-04-06 11:19:54.005 DEBUG 57700 --- [ main] o.s.c.a.ClassPathBeanDefinitionScanner : Identified candidate component class: file [/Users/njari/X/util/target/classes/in/njari/util/src/controller/UtilController.class]
2022-04-06 11:19:54.615 INFO 57700 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-04-06 11:19:54.627 INFO 57700 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-04-06 11:19:54.627 INFO 57700 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.31]
2022-04-06 11:19:54.708 INFO 57700 --- [ main] o.a.c.c.C.[.[localhost].[/util-service] : Initializing Spring embedded WebApplicationContext
2022-04-06 11:19:54.709 INFO 57700 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 830 ms
2022-04-06 11:19:54.861 INFO 57700 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '/util-service'
2022-04-06 11:19:54.866 INFO 57700 --- [ main] in.njari.util.UtilApplication : Started UtilApplication in 6.463 seconds (JVM running for 6.993)
I tried hitting the api with the url :
http://localhost:8080/util-service/util and this throws up a 404 error.
So even though the controller is picked up for component scanning(according to the logs), the request within it isn't mapped. Not sure why this is happening.
I suspect there is something wrong with the way i'm configuring my request here! Haven't been able to pinpoint what it really is though.
If you explicitly want to scan base packages, use
#SpringBootApplication(scanBasePackages = "in.njari")
Edit: Updating answer w.r.t. your code
Change spring-web dependency to
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
try removing
#ComponentScan(basePackages = "in.njari")
the annotation #RestController is a java bean that the system will recognize and initialize by its own, Other then that your code seems to work I have tested it.
Related
I am trying to build a Kafka Consumer using Spring Boot. It's a multi-module Maven project where consumer-app is the SpringBoot application and rest of the modules are added as dependencies to the parent project.
With this, I am able to build the project and run the app as well. But the app is not connecting to the Kafka broker (bootstrap server on my local).
Log ends as this:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.12.RELEASE)
2022-06-28 20:26:50.849 INFO 17284 --- [ restartedMain] c.t.c.c.c.CardConsumerApplication : Starting CardConsumerApplication on WorkIsOn with PID 17284 (C:\Users\myuser\Workspace\card-consumer\card-consumer\target\classes started by myuser in C:\Users\myuser\Workspace\card-consumer)
2022-06-28 20:26:50.851 INFO 17284 --- [ restartedMain] c.t.c.c.c.CardConsumerApplication : No active profile set, falling back to default profiles: default
2022-06-28 20:26:50.900 INFO 17284 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2022-06-28 20:26:50.901 INFO 17284 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2022-06-28 20:26:51.778 INFO 17284 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9090 (http)
2022-06-28 20:26:51.784 INFO 17284 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-06-28 20:26:51.785 INFO 17284 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.46]
2022-06-28 20:26:51.850 INFO 17284 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-06-28 20:26:51.850 INFO 17284 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 949 ms
2022-06-28 20:26:51.977 INFO 17284 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2022-06-28 20:26:52.157 INFO 17284 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2022-06-28 20:26:52.182 INFO 17284 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 9090 (http) with context path ''
2022-06-28 20:26:52.189 INFO 17284 --- [ restartedMain] c.t.c.c.c.CardConsumerApplication : Started CardConsumerApplication in 1.688 seconds (JVM running for 3.215)
Now, I made another app with the code of Kafka consumer module in a non-multi-module Maven project, I am able to connect to the Kafka's bootstrap server and this app is able to get the message as well.
I have same SpringBoot configuration placed in both the application/project.
Please help me understand how to make this multi-module Maven app work.
i have a application.yml to auto-creation some table:
## JDBC part
spring:
config:
activate:
on-profile: local
enabled: true
datasource:
url: jdbc:mysql://localhost:3306/kazi?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
driver-class-name: com.mysql.cj.jdbc.Driver
username: emo
password: 123qwe
jpa:
show-sql: true
database-platform: org.hibernate.dialect.MySQL8Dialect
hibernate:
ddl-auto: update
liquibase:
change-log: classpath:liquibase/changelog.xml
#spring.jpa.properties.hibernate.hbm2ddl.import_files=import.sql
main class:
#EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
#SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Log
/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/bin/java -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=57211:/Applications/IntelliJ IDEA.app/Contents/bin -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -Dfile.encoding=UTF-8 -classpath /Users/emoleumassi/Documents/Projects/me/kazi/kazi-core/target/classes:/Users/emoleumassi/.m2/repository/org/liquibase/liquibase-core/4.5.0/liquibase-core-4.5.0.jar:/Users/emoleumassi/.m2/repository/javax/xml/bind/jaxb-api/2.3.1/jaxb-api-2.3.1.jar:/Users/emoleumassi/.m2/repository/javax/activation/javax.activation-api/1.2.0/javax.activation-api-1.2.0.jar:/Users/emoleumassi/.m2/repository/org/liquibase/liquibase-maven-plugin/3.8.2/liquibase-maven-plugin-3.8.2.jar:/Users/emoleumassi/.m2/repository/org/apache/maven/maven-plugin-api/2.0/maven-plugin-api-2.0.jar:/Users/emoleumassi/.m2/repository/org/apache/maven/maven-project/2.0/maven-project-2.0.jar:/Users/emoleumassi/.m2/repository/org/apache/maven/maven-profile/2.0/maven-profile-2.0.jar:/Users/emoleumassi/.m2/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.jar:/Users/emoleumassi/.m2/repository/org/apache/maven/maven-artifact-manager/2.0/maven-artifact-manager-2.0.jar:/Users/emoleumassi/.m2/repository/org/apache/maven/maven-repository-metadata/2.0/maven-repository-metadata-2.0.jar:/Users/emoleumassi/.m2/repository/org/apache/maven/wagon/wagon-provider-api/1.0-alpha-5/wagon-provider-api-1.0-alpha-5.jar:/Users/emoleumassi/.m2/repository/org/codehaus/plexus/plexus-utils/1.0.4/plexus-utils-1.0.4.jar:/Users/emoleumassi/.m2/repository/org/apache/maven/maven-artifact/2.0/maven-artifact-2.0.jar:/Users/emoleumassi/.m2/repository/org/codehaus/plexus/plexus-container-default/1.0-alpha-8/plexus-container-default-1.0-alpha-8.jar:/Users/emoleumassi/.m2/repository/junit/junit/4.13.2/junit-4.13.2.jar:/Users/emoleumassi/.m2/repository/org/hamcrest/hamcrest-core/2.2/hamcrest-core-2.2.jar:/Users/emoleumassi/.m2/repository/classworlds/classworlds/1.1-alpha-2/classworlds-1.1-alpha-2.jar:/Users/emoleumassi/.m2/repository/org/slf4j/slf4j-api/1.7.32/slf4j-api-1.7.32.jar:/Users/emoleumassi/.m2/repository/ch/qos/logback/logback-classic/1.2.9/logback-classic-1.2.9.jar:/Users/emoleumassi/.m2/repository/ch/qos/logback/logback-core/1.2.9/logback-core-1.2.9.jar:/Users/emoleumassi/.m2/repository/com/fasterxml/jackson/module/jackson-module-jaxb-annotations/2.13.1/jackson-module-jaxb-annotations-2.13.1.jar:/Users/emoleumassi/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.13.1/jackson-annotations-2.13.1.jar:/Users/emoleumassi/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.13.1/jackson-core-2.13.1.jar:/Users/emoleumassi/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.13.1/jackson-databind-2.13.1.jar:/Users/emoleumassi/.m2/repository/jakarta/xml/bind/jakarta.xml.bind-api/2.3.3/jakarta.xml.bind-api-2.3.3.jar:/Users/emoleumassi/.m2/repository/jakarta/activation/jakarta.activation-api/1.2.2/jakarta.activation-api-1.2.2.jar:/Users/emoleumassi/.m2/repository/org/springframework/boot/spring-boot-starter-data-jpa/2.6.2/spring-boot-starter-data-jpa-2.6.2.jar:/Users/emoleumassi/.m2/repository/org/springframework/boot/spring-boot-starter-aop/2.6.2/spring-boot-starter-aop-2.6.2.jar:/Users/emoleumassi/.m2/repository/org/aspectj/aspectjweaver/1.9.7/aspectjweaver-1.9.7.jar:/Users/emoleumassi/.m2/repository/org/springframework/boot/spring-boot-starter-jdbc/2.6.2/spring-boot-starter-jdbc-2.6.2.jar:/Users/emoleumassi/.m2/repository/com/zaxxer/HikariCP/4.0.3/HikariCP-4.0.3.jar:/Users/emoleumassi/.m2/repository/org/springframework/spring-jdbc/5.3.14/spring-jdbc-5.3.14.jar:/Users/emoleumassi/.m2/repository/jakarta/transaction/jakarta.transaction-api/1.3.3/jakarta.transaction-api-1.3.3.jar:/Users/emoleumassi/.m2/repository/jakarta/persistence/jakarta.persistence-api/2.2.3/jakarta.persistence-api-2.2.3.jar:/Users/emoleumassi/.m2/repository/org/hibernate/hibernate-core/5.6.3.Final/hibernate-core-5.6.3.Final.jar:/Users/emoleumassi/.m2/repository/org/jboss/logging/jboss-logging/3.4.2.Final/jboss-logging-3.4.2.Final.jar:/Users/emoleumassi/.m2/repository/net/bytebuddy/byte-buddy/1.11.22/byte-buddy-1.11.22.jar:/Users/emoleumassi/.m2/repository/antlr/antlr/2.7.7/antlr-2.7.7.jar:/Users/emoleumassi/.m2/repository/org/jboss/jandex/2.2.3.Final/jandex-2.2.3.Final.jar:/Users/emoleumassi/.m2/repository/com/fasterxml/classmate/1.5.1/classmate-1.5.1.jar:/Users/emoleumassi/.m2/repository/org/hibernate/common/hibernate-commons-annotations/5.1.2.Final/hibernate-commons-annotations-5.1.2.Final.jar:/Users/emoleumassi/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.5/jaxb-runtime-2.3.5.jar:/Users/emoleumassi/.m2/repository/org/glassfish/jaxb/txw2/2.3.5/txw2-2.3.5.jar:/Users/emoleumassi/.m2/repository/com/sun/istack/istack-commons-runtime/3.0.12/istack-commons-runtime-3.0.12.jar:/Users/emoleumassi/.m2/repository/com/sun/activation/jakarta.activation/1.2.2/jakarta.activation-1.2.2.jar:/Users/emoleumassi/.m2/repository/org/springframework/data/spring-data-jpa/2.6.0/spring-data-jpa-2.6.0.jar:/Users/emoleumassi/.m2/repository/org/springframework/data/spring-data-commons/2.6.0/spring-data-commons-2.6.0.jar:/Users/emoleumassi/.m2/repository/org/springframework/spring-orm/5.3.14/spring-orm-5.3.14.jar:/Users/emoleumassi/.m2/repository/org/springframework/spring-context/5.3.14/spring-context-5.3.14.jar:/Users/emoleumassi/.m2/repository/org/springframework/spring-tx/5.3.14/spring-tx-5.3.14.jar:/Users/emoleumassi/.m2/repository/org/springframework/spring-beans/5.3.14/spring-beans-5.3.14.jar:/Users/emoleumassi/.m2/repository/org/springframework/spring-aspects/5.3.14/spring-aspects-5.3.14.jar:/Users/emoleumassi/.m2/repository/mysql/mysql-connector-java/8.0.27/mysql-connector-java-8.0.27.jar:/Users/emoleumassi/.m2/repository/org/springframework/boot/spring-boot-starter/2.6.2/spring-boot-starter-2.6.2.jar:/Users/emoleumassi/.m2/repository/org/springframework/boot/spring-boot-starter-logging/2.6.2/spring-boot-starter-logging-2.6.2.jar:/Users/emoleumassi/.m2/repository/org/apache/logging/log4j/log4j-to-slf4j/2.17.0/log4j-to-slf4j-2.17.0.jar:/Users/emoleumassi/.m2/repository/org/apache/logging/log4j/log4j-api/2.17.0/log4j-api-2.17.0.jar:/Users/emoleumassi/.m2/repository/org/slf4j/jul-to-slf4j/1.7.32/jul-to-slf4j-1.7.32.jar:/Users/emoleumassi/.m2/repository/org/yaml/snakeyaml/1.29/snakeyaml-1.29.jar:/Users/emoleumassi/.m2/repository/org/hamcrest/hamcrest/2.2/hamcrest-2.2.jar:/Users/emoleumassi/.m2/repository/org/springframework/spring-core/5.3.14/spring-core-5.3.14.jar:/Users/emoleumassi/.m2/repository/org/springframework/spring-jcl/5.3.14/spring-jcl-5.3.14.jar:/Users/emoleumassi/.m2/repository/org/springframework/boot/spring-boot-starter-security/2.6.2/spring-boot-starter-security-2.6.2.jar:/Users/emoleumassi/.m2/repository/org/springframework/spring-aop/5.3.14/spring-aop-5.3.14.jar:/Users/emoleumassi/.m2/repository/org/springframework/security/spring-security-config/5.6.1/spring-security-config-5.6.1.jar:/Users/emoleumassi/.m2/repository/org/springframework/security/spring-security-core/5.6.1/spring-security-core-5.6.1.jar:/Users/emoleumassi/.m2/repository/org/springframework/security/spring-security-crypto/5.6.1/spring-security-crypto-5.6.1.jar:/Users/emoleumassi/.m2/repository/org/springframework/security/spring-security-web/5.6.1/spring-security-web-5.6.1.jar:/Users/emoleumassi/.m2/repository/org/springframework/spring-expression/5.3.14/spring-expression-5.3.14.jar:/Users/emoleumassi/.m2/repository/org/springframework/spring-web/5.3.14/spring-web-5.3.14.jar:/Users/emoleumassi/.m2/repository/org/springframework/boot/spring-boot-starter-tomcat/2.6.2/spring-boot-starter-tomcat-2.6.2.jar:/Users/emoleumassi/.m2/repository/jakarta/annotation/jakarta.annotation-api/1.3.5/jakarta.annotation-api-1.3.5.jar:/Users/emoleumassi/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.56/tomcat-embed-core-9.0.56.jar:/Users/emoleumassi/.m2/repository/org/apache/tomcat/embed/tomcat-embed-el/9.0.56/tomcat-embed-el-9.0.56.jar:/Users/emoleumassi/.m2/repository/org/apache/tomcat/embed/tomcat-embed-websocket/9.0.56/tomcat-embed-websocket-9.0.56.jar:/Users/emoleumassi/.m2/repository/org/springframework/boot/spring-boot-devtools/2.6.2/spring-boot-devtools-2.6.2.jar:/Users/emoleumassi/.m2/repository/org/springframework/boot/spring-boot/2.6.2/spring-boot-2.6.2.jar:/Users/emoleumassi/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/2.6.2/spring-boot-autoconfigure-2.6.2.jar:/Users/emoleumassi/.m2/repository/org/springframework/boot/spring-boot-starter-actuator/2.6.2/spring-boot-starter-actuator-2.6.2.jar:/Users/emoleumassi/.m2/repository/org/springframework/boot/spring-boot-actuator-autoconfigure/2.6.2/spring-boot-actuator-autoconfigure-2.6.2.jar:/Users/emoleumassi/.m2/repository/org/springframework/boot/spring-boot-actuator/2.6.2/spring-boot-actuator-2.6.2.jar:/Users/emoleumassi/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.13.1/jackson-datatype-jsr310-2.13.1.jar:/Users/emoleumassi/.m2/repository/io/micrometer/micrometer-core/1.8.1/micrometer-core-1.8.1.jar:/Users/emoleumassi/.m2/repository/org/hdrhistogram/HdrHistogram/2.1.12/HdrHistogram-2.1.12.jar:/Users/emoleumassi/.m2/repository/org/latencyutils/LatencyUtils/2.0.3/LatencyUtils-2.0.3.jar:/Users/emoleumassi/.m2/repository/org/projectlombok/lombok/1.18.16/lombok-1.18.16.jar:/Users/emoleumassi/.m2/repository/org/projectlombok/lombok-mapstruct-binding/0.2.0/lombok-mapstruct-binding-0.2.0.jar com.kazi.Application
19:21:19.040 [Thread-0] DEBUG org.springframework.boot.devtools.restart.classloader.RestartClassLoader - Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader#32d703c9
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.6.2)
2022-01-24 19:21:19.677 INFO 28392 --- [ restartedMain] com.kazi.Application : Starting Application using Java 11.0.11 on FVFFF491Q05N.fritz.box with PID 28392 (/kazi/kazi-core/target/classes started by in //kazi)
2022-01-24 19:21:19.678 INFO 28392 --- [ restartedMain] com.kazi.Application : No active profile set, falling back to default profiles: default
2022-01-24 19:21:19.743 INFO 28392 --- [ restartedMain] o.s.b.devtools.restart.ChangeableUrls : The Class-Path manifest attribute in //.m2/repository/org/liquibase/liquibase-core/4.5.0/liquibase-core-4.5.0.jar referenced one or more files that do not exist: file://.m2/repository/org/liquibase/liquibase-core/4.5.0/snakeyaml-1.27.jar
2022-01-24 19:21:19.745 INFO 28392 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2022-01-24 19:21:19.745 INFO 28392 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2022-01-24 19:21:21.125 INFO 28392 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-01-24 19:21:21.132 INFO 28392 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-01-24 19:21:21.132 INFO 28392 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.56]
2022-01-24 19:21:21.208 INFO 28392 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-01-24 19:21:21.209 INFO 28392 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1464 ms
2022-01-24 19:21:21.656 INFO 28392 --- [ restartedMain] .s.s.UserDetailsServiceAutoConfiguration :
Using generated security password: 6b57bd8f-9f75-40b5-8805-d33182a6782f
2022-01-24 19:21:21.719 INFO 28392 --- [ restartedMain] o.s.s.web.DefaultSecurityFilterChain : Will secure any request with [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#585f2fd, org.springframework.security.web.context.SecurityContextPersistenceFilter#217e757f, org.springframework.security.web.header.HeaderWriterFilter#54ef1e31, org.springframework.security.web.csrf.CsrfFilter#1323ecfd, org.springframework.security.web.authentication.logout.LogoutFilter#50c74237, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#31cfd78a, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter#175a6ba7, org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter#74ce9809, org.springframework.security.web.authentication.www.BasicAuthenticationFilter#1143ca59, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#4de8bf20, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#272d7d98, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#7bd095cb, org.springframework.security.web.session.SessionManagementFilter#7d64f793, org.springframework.security.web.access.ExceptionTranslationFilter#8fd5915, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#53681a29]
2022-01-24 19:21:21.782 INFO 28392 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2022-01-24 19:21:21.835 INFO 28392 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-01-24 19:21:21.856 INFO 28392 --- [ restartedMain] com.kazi.Application : Started Application in 2.798 seconds (JVM running for 3.673)
The application start successfully but the tables haven't created. I tried it with ddl-auto: create und have the same problem.
I think the application.yml isn't load.
The location:
I think no Datasource in this app.
#EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
try this
#EnableAutoConfiguration
I'm trying to build a secured (JWT) reactive (webflow) spring-boot app, but can't get it starting.
I've built a servlet companion app with same components and similar config which works fine, but it looks like something is missing in my conf and can't figure out what.
#SpringBootApplication(scanBasePackageClasses = { ReactiveApp.class, GreetingHandler.class, GreetingRouter.class,
MessageService.class, MessageServiceImpl.class })
public class ReactiveApp {
public static void main(String[] args) {
SpringApplication.run(ReactiveApp.class, args);
}
#EnableWebFluxSecurity
#EnableReactiveMethodSecurity
public class ReactiveSecurityConfig {
#Value("${spring.security.oauth2.resourceserver.jwt.issuer-uri}")
String issuerUri;
#Bean
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
// #formatter:off
http.csrf().disable().httpBasic().disable().formLogin().disable();
http.authorizeExchange().pathMatchers("/secret-endpoint").hasAnyRole("AUTHORIZED_PERSONNEL").anyExchange()
.authenticated();
http.oauth2ResourceServer().jwt().jwtAuthenticationConverter(authExtractor());
// #formatter:on
return http.build();
}
#Bean
ReactiveJwtDecoder jwtDecoder() {
return ReactiveJwtDecoders.fromOidcIssuerLocation(issuerUri);
}
#Bean
public AuthenticationConverter authExtractor() {
KeycloackOidcIdAuthenticationConverter extractor = new KeycloackOidcIdAuthenticationConverter() {
};
return jwt -> Mono.just(jwt).map(extractor::convert);
}
}
private static interface AuthenticationConverter extends Converter<Jwt, Mono<AbstractAuthenticationToken>> {
}
}
Logs are minimal :/
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.4.RELEASE)
2020-02-12 18:47:23.975 INFO 13320 --- [ main] c.c.s.sample.reactive.ReactiveApp : Starting ReactiveApp on LAPTOP-JEREM with PID 13320 (C:\Users\jwacongne\dev\workspaces\libs\spring-addons\spring-security-test-keycloack-addons\target\test-classes started by jwacongne in C:\Users\jwacongne\dev\workspaces\libs\spring-addons\spring-security-test-keycloack-addons)
2020-02-12 18:47:23.978 INFO 13320 --- [ main] c.c.s.sample.reactive.ReactiveApp : No active profile set, falling back to default profiles: default
2020-02-12 18:47:25.091 INFO 13320 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8090 (https)
2020-02-12 18:47:25.109 INFO 13320 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-02-12 18:47:25.110 INFO 13320 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.30]
2020-02-12 18:47:25.259 INFO 13320 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-02-12 18:47:25.260 INFO 13320 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1238 ms
2020-02-12 18:47:26.054 INFO 13320 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-02-12 18:47:26.234 WARN 13320 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jwtDecoderWebSecurityConfigurerAdapter': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.security.config.annotation.ObjectPostProcessor<?>' available
2020-02-12 18:47:26.235 INFO 13320 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
2020-02-12 18:47:26.237 INFO 13320 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2020-02-12 18:47:26.249 INFO 13320 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-02-12 18:47:26.386 ERROR 13320 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
A component required a bean of type 'org.springframework.security.config.annotation.ObjectPostProcessor' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.security.config.annotation.ObjectPostProcessor' in your configuration.
While debugging, I can see exception with following message is thrown:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jwtDecoderWebSecurityConfigurerAdapter': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.security.config.annotation.ObjectPostProcessor<?>' available
Spring-boot version: 2.2.4
I have created a simple Spring Boot v2.1.10 application with Gradle v5.6.4 and trying to run it in Docker v18.09.9, build 1752eb3. The application is working locally, but when I run it in Docker, the webpage doesn't load in the browser. Though, it is starting in the Docker console properly without any error.
Dockerfile content
FROM java:8
EXPOSE 9090:8181
ADD /build/libs/docker-app-0.0.1-SNAPSHOT.jar docker-app-0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java","-jar","docker-app-0.0.1-SNAPSHOT.jar"]
Springboot app controller
#RestController
public class Resource {
#GetMapping(value = "/home")
public String home() {
return "<h1>up!!!.....running from docker!!!</h1>";
}
}
Docker run command
:~/java-project/docker-app$ sudo docker run -p 9090:8181 springboot
Docker console output
:~/java-project/docker-app$ sudo docker run -p 9090:8181 springboot
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.10.RELEASE)
2019-11-19 20:38:03.870 INFO 1 --- [ main] com.DockerAppApplication : Starting DockerAppApplication on 93febc16ff7d with PID 1 (/docker-app-0.0.1-SNAPSHOT.jar started by root in /)
2019-11-19 20:38:03.877 INFO 1 --- [ main] com.DockerAppApplication : No active profile set, falling back to default profiles: default
2019-11-19 20:38:06.459 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9090 (http)
2019-11-19 20:38:06.528 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-11-19 20:38:06.528 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.27]
2019-11-19 20:38:06.669 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-11-19 20:38:06.669 INFO 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2642 ms
2019-11-19 20:38:07.012 INFO 1 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-11-19 20:38:07.333 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 9090 (http) with context path ''
2019-11-19 20:38:07.339 INFO 1 --- [ main] com.DockerAppApplication : Started DockerAppApplication in 4.276 seconds (JVM running for 5.029)
NOTE: When I give the same port number(sudo docker run -p 9090:9090 springboot) in run command and in Dockerfile, then it's working properly.
What's different in case of different port numbers in the docker run command?
TL;DR
Change your mapping to -p 8181:9090
You got that the wrong way. The -p 9090:8181 setting will expose the container's port 8181 on the host's port 9090 — assuming that port is not in use. You can effectively use the port 9090 on the host, but the Spring Boot application in the container is not listening on 8181, so you won't get any response back from it.
When you do -p 9090:9090 you are correctly exposing 9090 on the host and the container; again, the Spring Boot application is effectively listening on port 9090, so you are able hit the Spring Boot application and get something back.
In any case, what you are looking for is -p 8181:9090. That will let you use the application on port 8181 in the browser/host, while the Spring Boot application uses 9090.
I defined a simple SpringApplicationRunListener implementation with the following method:
#Override
public void finished(ConfigurableApplicationContext configurableApplicationContext, Throwable throwable) {
logger.info("It's finished");
}
When I run without any Spring cloud dependency I get the following log:
2016-04-27 10:37:37.702 INFO 5720 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-04-27 10:37:37.703 INFO 5720 --- [ main] b.a.test.LazyFilterRuntimeListener : It's finished
However, when I add the following dependency:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
Then the "It's finished" line is logged twice, once at the end (like without Spring cloud/Eureka) and once at the start, even before the Spring boot logo appears:
2016-04-27 10:37:35.500 INFO 5720 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#255b53dc: startup date [Wed Apr 27 10:37:35 CEST 2016]; root of context hierarchy
2016-04-27 10:37:35.638 INFO 5720 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2016-04-27 10:37:35.785 INFO 5720 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'encrypt.CONFIGURATION_PROPERTIES' of type [class org.springframework.cloud.bootstrap.encrypt.KeyProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-04-27 10:37:35.786 INFO 5720 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'encryptionBootstrapConfiguration' of type [class org.springframework.cloud.bootstrap.encrypt.EncryptionBootstrapConfiguration$$EnhancerBySpringCGLIB$$268d5fc8] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-04-27 10:37:35.839 INFO 5720 --- [ main] b.c.test.LazyFilterRuntimeListener : It's finished
2016-04-27 10:37:35.842 INFO 5720 --- [ main] be.company.test.TestApplication : Started TestApplication in 0.499 seconds (JVM running for 0.86)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.2.7.RELEASE)
...
2016-04-27 10:37:37.702 INFO 5720 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-04-27 10:37:37.703 INFO 5720 --- [ main] b.c.test.LazyFilterRuntimeListener : It's finished
2016-04-27 10:37:37.703 INFO 5720 --- [ main] be.company.test.TestApplication : Started TestApplication in 2.423 seconds (JVM running for 2.721)
It also mentions the line "Started Application in ..." twice.
Is there a particular reason for this behaviour? I'm trying to write a SpringApplicationRunListener that relies on specific beans to have been created. However, if I add spring cloud, the first time it reaches the finished() method, the context is not yet created, so it currently throws an error.
Actually there is a issue of double calling for logging. By default Spring Boot sets up INFO level logging.
Previous version of spring boot before 1.3, as you are using 1.2.7 Then it uses
if you can't override spring boot's CONSOLE_LOG_PATTERN with your MDC
value added, then it seems you have to live with every log message
being written twice! (once with the spring boot console appender and
once with your console appender with MDC added to the pattern)
But in spring boot 1.3
In newer versions of Spring Boot you can easily just include the base.xml from Spring Boot and create the following logback.xml.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<root level="INFO">
<appender-ref ref="FILE" />
</root>
</configuration>
For more details, you can follow: How to disable logback ConsoleAppender in Spring Boot
Resource Link:
https://github.com/spring-projects/spring-boot/issues/1788
https://github.com/spring-projects/spring-boot/issues/2558