I made a simple Jar with spring boot in which I simply placed a single class called IngressFilter whose job is to monitor network calls. Let's call this Jar Network-Tracer for now.
The IngressFilter and Pom.xml code can be found below.
IngressFilter.Java
#Component
#Slf4j
public class IngressFilter extends OncePerRequestFilter {
IngressFilter() {
log.info("Started Ingress Filter");
}
#Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
log.info("Started network call");
filterChain.doFilter(request, response);
log.info("call finished");
}
}
Pom.xml
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.demo.networktracer</groupId>
<artifactId>network-tracer</artifactId>
<version>0.0.2</version>
<name>network-tracer</name>
<packaging>jar</packaging>
<url>http://maven.apache.org</url>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Nothing special in the code, just a simple jar.
However, when I include this jar as a dependency in one of the spring boot applications, an issue arises.
Assume the application is
Weather Application
.
Below is the Pom.xml
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.poc</groupId>
<artifactId>weather</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>weather</name>
<description>Weather Calling Service</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.4</version>
</dependency>
<dependency>
<groupId>com.demo.networktracer</groupId>
<artifactId>network-tracer</artifactId>
<version>0.0.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
This code initializes when I try to run it. However, when I call one of the weather application's APIs, the Filter isn't called.
I'm also printing logs from the Weather Application for further information.
2022-04-21 07:42:49,128 INFO [main] org.springframework.boot.SpringApplication: No active profile set, falling back to 1 default profile: "default"
2022-04-21 07:42:49,761 INFO [main] org.springframework.boot.web.embedded.tomcat.TomcatWebServer: Tomcat initialized with port(s): 8080 (http)
2022-04-21 07:42:49,765 INFO [main] org.apache.juli.logging.DirectJDKLog: Initializing ProtocolHandler ["http-nio-8080"]
2022-04-21 07:42:49,765 INFO [main] org.apache.juli.logging.DirectJDKLog: Starting service [Tomcat]
2022-04-21 07:42:49,765 INFO [main] org.apache.juli.logging.DirectJDKLog: Starting Servlet engine: [Apache Tomcat/9.0.60]
2022-04-21 07:42:49,814 INFO [main] org.apache.juli.logging.DirectJDKLog: Initializing Spring embedded WebApplicationContext
2022-04-21 07:42:49,814 INFO [main] org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext: Root WebApplicationContext: initialization completed in 633 ms
2022-04-21 07:42:49,976 INFO [main] org.apache.juli.logging.DirectJDKLog: Starting ProtocolHandler ["http-nio-8080"]
2022-04-21 07:42:49,997 INFO [main] org.springframework.boot.web.embedded.tomcat.TomcatWebServer: Tomcat started on port(s): 8080 (http) with context path ''
2022-04-21 07:42:50,009 INFO [main] org.springframework.boot.StartupInfoLogger: Started WeatherApplication in 1.149 seconds (JVM running for 1.605)
I looked everywhere on the internet for information on this, but nothing came up.
Please assist me in determining why the network-tracer Ingressfilter is not being invoked.
Related
I have multi module project with Spring boot and an external server Weblogic.
These are modules:
dao
service
web
pom.xml (dao) .
It is the work with database (repository, entities)
<?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">
<parent>
<artifactId>gov-multiple-modules</artifactId>
<groupId>gov</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.dao</groupId>
<artifactId>dao</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<output.directory.jdbc.oracle>${project.basedir}/src/main/resources</output.directory.jdbc.oracle>
</properties>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc</artifactId>
<version>6</version>
<scope>system</scope>
<systemPath>${output.directory.jdbc.oracle}/lib/ojdbc6.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Dfile.encoding=UTF8</argLine>
</configuration>
</plugin>
</plugins>
</build>
</project>
pom.xml (service )
<?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">
<parent>
<artifactId>gov-multiple-modules</artifactId>
<groupId>gov</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.service</groupId>
<artifactId>service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.dao</groupId>
<artifactId>dao</artifactId>
<version>${version.dao.module}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${version.mapstruct}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Dfile.encoding=UTF8</argLine>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.apache.maven.plugins}</version>
<groupId>org.apache.maven.plugins</groupId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${version.mapstruct}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
pom.xml (web )
It is the work with requests from clients (Contoroller and RestControllers).
There is an entry point in app.
<?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">
<parent>
<artifactId>gov-multiple-modules</artifactId>
<groupId>gov</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.web</groupId>
<artifactId>web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.service</groupId>
<artifactId>service</artifactId>
<version>${version.service.module}</version>
</dependency>
</dependencies>
<build>
<finalName>weblogic-war-gov</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Dfile.encoding=UTF8</argLine>
</configuration>
</plugin>
<plugin> <!--It is for convert beans-->
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.apache.maven.plugins}</version>
<groupId>org.apache.maven.plugins</groupId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${version.mapstruct}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
pom.xml (parrent)
<?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>
<modules>
<module>dao</module>
<module>service</module>
<module>web</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>gov</groupId>
<artifactId>gov-multiple-modules</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>gov-multiple-modules</name>
<description>project with Spring Boot for multiple module applications</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<version.apache.maven.plugins>3.8.1</version.apache.maven.plugins>
<version.mapstruct>1.3.0.Final</version.mapstruct>
<version.apache.common.lang3>3.9</version.apache.common.lang3>
<version.apache.commons.text>1.8</version.apache.commons.text>
<version.apache.commons.beanutils>1.9.4</version.apache.commons.beanutils>
<version.hibernate.validator>6.0.17.Final</version.hibernate.validator>
<version.reflection>0.9.11</version.reflection>
<version.dao.module>0.0.1-SNAPSHOT</version.dao.module>
<version.service.module>0.0.1-SNAPSHOT</version.service.module>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--This artifact need for testing that to find classes into classpath-->
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>${version.reflection}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${version.apache.common.lang3}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>${version.apache.commons.text}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>${version.apache.commons.beanutils}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
</dependencies>
</project>
An entry point
#SpringBootConfiguration
#SpringBootApplication
#EnableJpaRepositories(basePackages = {"com.dao", "com.service"})
#EntityScan(basePackages = {"com.dao"})
#ComponentScan(basePackages = {"com.service", "com.dao", "com.web"})
public class WebSpringBootJarApplication
extends SpringBootServletInitializer
implements WebApplicationInitializer {
private static final Logger LOGGER = LoggerFactory.getLogger( WebSpringBootJarApplication.class );
public static void main(String[] args) {
SpringApplication.run(WebSpringBootJarApplication.class, args);
LOGGER.info("Start an application...");
}
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
LOGGER.info("There is building the web application!");
return builder.sources(WebSpringBootJarApplication.class);
}
}
src/main/webapp/WEB-INF/weblogic.xml
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app
xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
https://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd
http://xmlns.oracle.com/weblogic/weblogic-web-app
https://xmlns.oracle.com/weblogic/weblogic-web-app/1.9/weblogic-web-app.xsd">
<wls:context-root>sun</wls:context-root>
</wls:weblogic-web-app>
After running I must see the page the greeting.
com.web.controller.index.IndexController
#Controller
public class IndexController {
#RequestMapping(value="/", method= RequestMethod.GET)
public String index() {
return "index";
}
}
src/main/resources/templates/index.html
But I get an error.
http://localhost:7001/sun/
in an browser
Error 500--Internal Server Error java.lang.NullPointerException at
weblogic.servlet.internal.ServletResponseImpl.sendContentError(ServletResponseImpl.java:738)
at
weblogic.servlet.internal.ServletResponseImpl.sendError(ServletResponseImpl.java:796)
at
weblogic.servlet.internal.ServletResponseImpl.sendError(ServletResponseImpl.java:713)
at
org.springframework.boot.web.servlet.support.ErrorPageFilter$ErrorWrapperResponse.sendErrorIfNecessary(ErrorPageFilter.java:349)
at
org.springframework.boot.web.servlet.support.ErrorPageFilter$ErrorWrapperResponse.getWriter(ErrorPageFilter.java:363)
at
org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$StaticView.render(ErrorMvcAutoConfiguration.java:227)
at
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1373)
at
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1118)
in console IDE
-"[2020-03-11 08:53:30,118] Artifact web:war exploded: Artifact is deployed successfully [2020-03-11 08:53:30,119] Artifact web:war
exploded: Deploy took 14,724 milliseconds
--11-03-2020 08:53:30.612 - INFO 17568 o.s.web.servlet.DispatcherServlet : Initializing Servlet
'dispatcherServlet' -"--11-03-2020 08:53:30.613 -DEBUG 17568
o.s.web.servlet.DispatcherServlet : Detected
StandardServletMultipartResolver -"--11-03-2020
08:53:30.621 -DEBUG 17568 o.s.web.servlet.DispatcherServlet :
enableLoggingRequestDetails='false': request parameters and headers
will be masked to prevent unsafe logging of potentially sensitive data
-"--11-03-2020 08:53:30.621 - INFO 17568 o.s.web.servlet.DispatcherServlet : Completed initialization
in 8 ms -"--11-03-2020 08:53:30.624 -DEBUG 17568
o.s.web.servlet.DispatcherServlet : GET "/sun/", parameters={}
-"--11-03-2020 08:53:30.628 -DEBUG 17568 s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to
com.web.controller.index.IndexController#index() -"--11-03-2020
08:53:30.647 -DEBUG 17568 o.s.w.s.v.ContentNegotiatingViewResolver :
Selected 'text/html' given [text/html, image/gif, image/jpeg,
/;q=.2] -"--11-03-2020 08:53:30.647 -DEBUG 17568 o.s.web.servlet.view.JstlView : View name 'index', model
{} -"--11-03-2020 08:53:30.652 -DEBUG 17568
o.s.web.servlet.view.JstlView : Forwarding to [index]
-"--11-03-2020 08:53:30.653 -DEBUG 17568 o.s.web.servlet.DispatcherServlet : "FORWARD" dispatch for GET
"/sun/index", parameters={} -"--11-03-2020 08:53:30.656 -DEBUG 17568
o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped to
ResourceHttpRequestHandler ["classpath:/META-INF/resources/",
"classpath:/resources/", "classpath:/static/", "classpath:/public/",
"/"] -"--11-03-2020 08:53:30.657 -DEBUG 17568
o.s.w.s.r.ResourceHttpRequestHandler : Resource not found
-"--11-03-2020 08:53:30.657 -DEBUG 17568 o.s.web.servlet.DispatcherServlet : Exiting from "FORWARD"
dispatch, status 404 -"--11-03-2020 08:53:30.664 -DEBUG 17568
o.s.web.servlet.DispatcherServlet : Error rendering view
[org.springframework.web.servlet.view.JstlView: name 'index'; URL
[index]]
- java.lang.NullPointerException: null at weblogic.servlet.internal.ServletResponseImpl.sendContentError(ServletResponseImpl.java:738)
~[com.oracle.weblogic.servlet.jar:12.2.1.4] at
weblogic.servlet.internal.ServletResponseImpl.sendError(ServletResponseImpl.java:796)
~[com.oracle.weblogic.servlet.jar:12.2.1.4] at
weblogic.servlet.internal.ServletResponseImpl.sendError(ServletResponseImpl.java:713)
~[com.oracle.weblogic.servlet.jar:12.2.1.4] at
org.springframework.boot.web.servlet.support.ErrorPageFilter$ErrorWrapperResponse.sendErrorIfNecessary(ErrorPageFilter.java:349)
~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE] at
org.springframework.boot.web.servlet.support.ErrorPageFilter$ErrorWrapperResponse.flushBuffer(ErrorPageFilter.java:343)
~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE] at
weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:336)
~[com.oracle.weblogic.servlet.jar:12.2.1.4] at
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:171)
~[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE] at
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:316)
~[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE] at
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1373)
[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE] at
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1118)
[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE] at
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1057)
[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE] at
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE] at
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE] at
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE] at
javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
[javax.servlet.javax.servlet-api.jar:3.1.0] at
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
[spring-webmvc-5.2.4.RELEASE.jar:5.2.4.RELEASE] ...
"java.lang.NullPointerException: null at
weblogic.servlet.internal.ServletResponseImpl.sendContentError(ServletResponseImpl.java:738)
at
weblogic.servlet.internal.ServletResponseImpl.sendError(ServletResponseImpl.java:796)
at
weblogic.servlet.internal.ServletResponseImpl.sendError(ServletResponseImpl.java:713)
at
org.springframework.boot.web.servlet.support.ErrorPageFilter$ErrorWrapperResponse.sendErrorIfNecessary(ErrorPageFilter.java:349)
at
org.springframework.boot.web.servlet.support.ErrorPageFilter$ErrorWrapperResponse.flushBuffer(ErrorPageFilter.java:343)
at
weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:336)
at
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:171)
...
--11-03-2020 08:53:30.666 -DEBUG 17568 o.s.web.servlet.DispatcherServlet : Failed to complete
request: java.lang.NullPointerException -"--11-03-2020
08:53:30.667 -ERROR 17568 o.s.b.w.servlet.support.ErrorPageFilter :
Forwarding to error page from request [/] due to exception [null]
It worked then the application was not multi module project.
Any ideas what the errors are? Please.
Solution
I needed to add an dependency - the thymeleaf. The static conten don't run without.
It need to add into pom's web-module.
<groupId>com.web</groupId>
<artifactId>web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
Not able to run spring boot application
Tried removing contents of /C:/Users/SaurKumar/.m2/repository/org/springframework/data/spring-data-commons/2.1.10.RELEASE/spring-data-commons-2.1.10.RELEASE.jar
:: Spring Boot :: (v2.1.8.RELEASE)
2019-09-08 05:22:05.217 INFO 2420 --- [ main] i.j.c.CourseApiDataApplication : Starting CourseApiDataApplication on BLRLW8166 with PID 2420 (C:\Users\SaurKumar\Downloads\course-api-data\course-api-data\target\classes started by saurkumar in C:\Users\SaurKumar\Downloads\course-api-data\course-api-data)
2019-09-08 05:22:05.222 INFO 2420 --- [ main] i.j.c.CourseApiDataApplication : No active profile set, falling back to default profiles: default
2019-09-08 05:22:06.110 INFO 2420 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-09-08 05:22:06.215 ERROR 2420 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.data.jpa.repository.config.JpaRepositoryConfigExtension.postProcess(JpaRepositoryConfigExtension.java:121)
The following method did not exist:
org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)Ljava/lang/String;
The method's class, org.springframework.data.repository.config.RepositoryConfigurationSource, is available from the following locations:
jar:file:/C:/Users/SaurKumar/.m2/repository/org/springframework/data/spring-data-commons/2.1.10.RELEASE/spring-data-commons-2.1.10.RELEASE.jar!/org/springframework/data/repository/config/RepositoryConfigurationSource.class
It was loaded from the following location:
file:/C:/Users/SaurKumar/.m2/repository/org/springframework/data/spring-data-commons/2.1.10.RELEASE/spring-data-commons-2.1.10.RELEASE.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.springframework.data.repository.config.RepositoryConfigurationSource
Process finished with exit code 1
-----------------------------------------
pom.xml
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>io.javabrains</groupId>
<artifactId>course-api-data</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>course-api-data</name>
<description>Demo project for Spring Boot</description>
<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.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.11.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
From the logs, it seems Spring is picking a different version for groupId org.springframework.data than the one provided with spring-data-jpa. If you could match the versions of spring-boot-starter-web and spring-data-jpa, it should work.
Quick fix being: Remove the version number for spring-data-jpa and it will by default take the latest version, which in your case is 2.1.10.RELEASE.
I have a rest service that does not work from tomcat container.Bellow are my pom.xml and classes.I would really appreciate some help.
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<artifactId>testcxf</artifactId>
<packaging>war</packaging>
testcxf
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-spring-boot-starter-jaxrs</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
the spring boot class:
#SpringBootApplication
public class TestcxfApplication extends SpringBootServletInitializer{
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) {
SpringApplication.run(TestcxfApplication.class, args);
}
}
the server class:
#Configuration
public class webs {
#Autowired
private Bus bus;
#Bean
public Server cxfRestServer(Hello hello) {
JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
factory.setBus(bus);
factory.setProvider(new JacksonJsonProvider());
factory.setServiceBean(hello);
factory.setAddress("/rest");
return factory.create();
}
}
and the hello class.
The log is like this:
Starting TestcxfApplication v1.5.10.RELEASE on Marius with PID 34204
(started by MARIUS$ in C:\Program Files\Apache Software
Foundation\Tomcat 8.5) No active profile set, falling back to default
profiles: default Refreshing
org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#4c65df69:
startup date [Mon Feb 12 16:17:09 EET 2018]; root of context hierarchy
Root WebApplicationContext: initialization completed in 288 ms Mapping
filter: 'errorPageFilter' to: [/*] Started TestcxfApplication in 0.879
seconds (JVM running for 4.531)
It says started but I can't access resources.I get 404 resources not found.
This shouldn't be needed:
#Configuration
public class webs {
#Autowired
private Bus bus;
#Bean
public Server cxfRestServer(Hello hello) {
JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
factory.setBus(bus);
factory.setProvider(new JacksonJsonProvider());
factory.setServiceBean(hello);
factory.setAddress("/rest");
return factory.create();
}
}
Let the CXF Spring Boot starter to handle it. Try also adding:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-service-description</artifactId>
<version>${cxf.version}</version>
</dependency>
and this config in application.yml:
# Spring MVC dispatcher servlet path needs to be different than CXF's
server.servlet-path: /
# http://cxf.apache.org/docs/springboot.html#SpringBoot-SpringBootCXFJAX-RSStarter
cxf:
path: /api # CXFServlet URL pattern
jaxrs:
component-scan: true
I have detailed this configuration / setup in my blog at Implementing APIs using Spring Boot, CXF and Swagger.
I am building a very basic spring-boot service using the inbuild tomcat server.
Pom looks like this :
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!--<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>-->
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-jdbc</artifactId>-->
<!--</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<!--<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
I am setting the port in the application.properties file as server.port=8089. There is one Ping URI added in the controller class as :
#RequestMapping("/ping")
#RestController
public class helloController {
#RequestMapping(method= RequestMethod.GET,produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> ping(){
return new ResponseEntity<>("Hello World Spring-boot app", HttpStatus.OK);
}
When I do a mvn clean package everything works fine and the build is a success. But when I run the application from the Main() this is what the log looks like :
2017-09-19 10:37:32.219 INFO 6436 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2017-09-19 10:37:32.290 INFO 6436 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#77f99a05: startup date [Tue Sep 19 10:37:32 PDT 2017]; root of context hierarchy
2017-09-19 10:37:33.782 INFO 6436 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-09-19 10:37:33.802 INFO 6436 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 2.043 seconds (JVM running for 2.802)
2017-09-19 10:37:33.802 INFO 6436 --- [ Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#77f99a05: startup date [Tue Sep 19 10:37:32 PDT 2017]; root of context hierarchy
2017-09-19 10:37:33.802 INFO 6436 --- [ Thread-2] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
The log is not showing what port the service is starting .
What else is to be done to start the service on the designated port and to keep the server up an running?
Solved this problem. Started the in built tomcat server using spring-boot:run option
I am trying to run a simple spring boot app in a stand-alone tomcat. I've tried following the reference docs and a few question/answers here but nothing seems to work. When tomcat starts up it deploys the app but completely ignores my Application class so no spring code gets loaded. I am sure it must be something simple I'm missing but...?
Here's the relevant output in the log file:
INFO: Deploying web application archive C:\dev\servers\apache-tomcat-7.0.75\webapps\bankweb-0.1.war
Feb 15, 2017 4:41:45 PM org.apache.catalina.startup.TldConfig execute
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list o
f JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and
JSP compilation time.
Feb 15, 2017 4:41:45 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deployment of web application archive C:\dev\servers\apache-tomcat-7.0.75\webapps\bankweb-0.1.war has finished in 3,595
ms
I've updated the Application class to extend SpringBootServletInitializer as per the docs:
#Configuration
#EnableAutoConfiguration
#ComponentScan
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(applicationClass, args);
}
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(applicationClass);
}
private static Class<Application> applicationClass = Application.class;
}
#RestController
class GreetingController {
#RequestMapping("/hello/{name}")
String hello(#PathVariable String name) {
return "Hello, " + name + "!";
}
}
And in the pom I've changed packaging to war and marked the embedded servlet container as provided:
<?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>
<groupId>it.ankle</groupId>
<artifactId>bankweb</artifactId>
<version>0.1</version>
<packaging>war</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.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>
<tomcat.version>7.0.69</tomcat.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
This is resolved, user error pretty much sums it up. I stripped everything back to remove all the optional spring modules, got it working, then added everything in bit by bit and it worked. I am not really accustomed to this spring boot stuff yet where functionality gets included just because you've configured a library in the pom. Thanks to anyone who took the time to read!