Unable to access the spring boot rest service from the WL server - spring-boot

I am very new to spring boot stuff. My question is about how to access a spring boot rest service deployed on weblogc server. I have successfully deployed (at least it seems from the WL console) the spring boot war file to the weblogic 12c container. But I am not able to access the service.
I am trying to use the following url to access:
http://host:port/myweb/resource/hello -- I am also not sure whether I should use WL server port on which the war is deployed or 8080 (default spring-boot port)
I have given all the code below. Am i missing anything? I would greatly appreciate any help
POM 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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example.demo</groupId>
<artifactId>SpringBootWL1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>SpringBootWL1</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<start-class>com.example.demo.SpringBootWl1Application</start-class>
</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-tomcat</artifactId>
<scope>provided</scope>
</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>
Rest Controller:
#RestController
#RequestMapping("/resource")
public class ResourceController {
#GetMapping("/hello")
String home() {
return "Hello World, How are you!";
}
Spring Boot Application
#SpringBootApplication
public class SpringBootWl1Application extends SpringBootServletInitializer implements WebApplicationInitializer {
public static void main(String[] args) {
SpringApplication.run(SpringBootWl1Application.class, args);
}
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(SpringBootWl1Application.class);
}
}
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://xmlns.oracle.com/weblogic/weblogic-web-app
http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
<wls:context-root>/myweb</wls:context-root>
<wls:container-descriptor>
<!-- <wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes> -->
<wls:prefer-application-packages>
<wls:package-name>org.slf4j.*</wls:package-name>
<wls:package-name>org.springframework.*</wls:package-name>
<wls:package-name>com.fasterxml.jackson.*</wls:package-name>
</wls:prefer-application-packages>
</wls:container-descriptor>
dispatcherServlet-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
</beans>

Your configuration seems ok. The default port of Weblogic is 7001, and every web application is deployed using this port.
To verify the deployment you can access to the console from (http://host:7001/console) and go to the Deployments section, there you must find your application deployed and it must be in State OK. Your can check there your web application context there.
One thing I noticed is your file is called: Weblogic.xml, but it must be called weblogic.xml all lower case.
Let me know if it is not working.

Related

Getting error while implementing a project to start spring cloud dataflow server on local

I am implementing very basic POC to start spring cloud dataflow server on local.
But I am getting below error :
Field appRegistry in
org.springframework.cloud.dataflow.completion.CompletionConfiguration
required a bean of type
'org.springframework.cloud.dataflow.registry.service.AppRegistryService'
that could not be found. The injection point has the following
annotations:
-#org.springframework.beans.factory.annotation.Autowired(required=true)
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ms</groupId>
<artifactId>abc-ui</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>abc-ui</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
</parent>
<properties>
<java.version>8</java.version>
<h2.version>1.4.193</h2.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-dataflow-server</artifactId>
<version>2.5.1.RELEASE</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
</dependencies>
</project>
Java file :
#EnableDataFlowServer
#SpringBootApplication(exclude = {CloudFoundryDeployerAutoConfiguration.class})
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class,args);
}
}
Is there any way to disable "AppRegistry" bean configuration?
I have implemented same project in another system and it is working fine.
Please let me know what mistake I am making.
The AppRegistryService is a required component for SCDF as it is the source of truth for all the applications registered for Stream and Task applications.
Hence, there is no way to disable it explicitly. But, you can still have a different implementation of AppRegistryService and have it override the existing one though.

Exception in thread "main" java.lang.NoSuchMethodError: org.slf4j.impl.StaticLoggerBinder.getSingleton()

Spring Boot Application
I am making a Tag Reader Application where am keep Getting This issue
Note: i am not using any Property file input
This my Simple Spring boot application
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class RfidReaderApplication {
public static void main(String[] args) {
SpringApplication.run(RfidReaderApplication.class, args);
}
}
*Pom.xml *
This pom configursation that i am using to build project and also have one external jar for OctaneSDKJava because it not reader OctaneSDKJava jar form pom so i added externally
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.Amazin.RFID.Reader</groupId>
<artifactId>RFID-Reader</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>RFID-Reader</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>com.octane</groupId>
<artifactId>OctaneSDKJava</artifactId>
<version>1.32.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Error Msg that i am getting
Exception in thread "main" java.lang.NoSuchMethodError: org.slf4j.impl.StaticLoggerBinder.getSingleton()Lorg/slf4j/impl/StaticLoggerBinder;
at org.springframework.boot.logging.logback.LogbackLoggingSystem.getLoggerContext(LogbackLoggingSystem.java:285)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:102)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:220)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:199)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:69)
at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:48)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:302)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
at com.Amazin.RFID.Reader.RfidReaderApplication.main(RfidReaderApplication.java:10)
As shown through the post linked in the comments, you are possibly missing some SLF4J dependencies. Another possibility, however, is that your dependencies actually have different versions of SLF4J, but since only one can be used there is a clash. See this SO post as well.
I would recommend explicitly using spring-boot-starter-log4j2 since you are using spring boot and going from there.

Unable to run localhost in Spring Boot application (Tomcat server)

I've been learning Spring using the following tutorials: https://www.youtube.com/playlist?list=PLqq-6Pq4lTTbx8p2oCgcAQGQyqN8XeA1x
I have created a Maven project and tried to run the Spring Boot application while referring to these videos:
https://www.youtube.com/watch?v=E7_a-kB46LU&index=9&list=PLqq-6Pq4lTTbx8p2oCgcAQGQyqN8XeA1x
I tried to run my Spring application on Tomcat server but the localhost isn't working. (Port 8080)
My pom.xml looks like this:
<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>io.javabrains.springbootquickstart</groupId>
<artifactId>course-api-new</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Java Brains Course API</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
</project>
CourseApiApp.java :
package io.javabrains.springbootstarter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class CourseApiApp {
public static void main(String[] args) {
SpringApplication.run(CourseApiApp.class, args);
}
}
According to the video localhost should display Whitelist error on running the application, but it doesn't run at all.
Any help would be appreciated, thanks!
I would suggest that you start your project from beginning. To create a valid spring-boot project you have a very good web based generator for spring-boot starter applications.
https://start.spring.io/
For a web application with an embedded tomcat you should use web project.
Using STS you can create the same by choosing new -> spring starter project.
A wizard will appear and you can choose your project informations:
And then in the second step you dependencies:
After generating your project your pom.xml should look like that:
<?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>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.4.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.8</java.version>
</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-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>
Your application should start normally and tomcat listens on localhost:8080.
EDIT
The starter just have a new design:
Solution: add web starter dependency to pom.xml for maven
No need to create new app. Just change this starter dependency to starter-web dependency:
Starter
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
Starter Web
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
You should try to run spring-boot as sudo
sudo mvn spring-boot:run
It could be possible that STS by default uses Tomcat version 7 and if you happen to use version 8, then would need to specify the same in pom.xml
<properties>
<tomcat.version>8.0.47</tomcat.version>
</properties>
I also faced the same issue. Try creating Spring Boot apprlication by choosing Spring Boot starter project in STS.
Right click on STS->New->Spring Starter Project->Give name and click on Next->Choose Web and tick mark on Web and search for Dev Tools and tick mark Dev Tools and click on Finish
Now click on the project and Run as Spring Boot Application.
In application.properties put server.port=8080
I faced the similar issue. I too was following the JavaBrains SpringBoot example. This is what I did:
I created a fresh spring boot project using STS tool and included the same code as provided by you and it worked!
You need to tell springboot where do you have to scan your reference classes
#SpringBootApplication
#ComponentScan(basePackages= {"com.testbean.controller", "com.testbean.model", "com.testbean.service"})
public class DemoApplication {
Use #ComponentScan("io.javabrains") and mention the package in which the Controller is present. eg.
#SpringBootApplication
#ComponentScan("io.javabrains")
public class CourseApiApp {
public static void main(String[] args) {
SpringApplication.run(CourseApiApp.class, args);
}
}
In a spring boot application, by default spring searches for components in the same package which is having the #SpringBootApplication annotation.
Follow this tutorial to setup JavaJDK, Tomcat and Maven: https://jeromejaglale.com/doc/spring4_tutorial/installation_macos
Next step move to Terminal app: type cd root_project and run sudo mvn spring-boot:run
I managed to solve with a tip above the server.port
I added as said: server.port = 8090 and it worked.
https://drive.google.com/file/d/1lZAEaD5VZdpnyffROn9X37mZm4vaQJ9G/view?usp=sharing

Got a 404 error on a simple rest service

i'm quite new to web developpement, I worked this summer on a web app on Spring, but the app was already set up, and was just doing some Java and AngularJS. But now i got some problem to start from scratch this type of application. I was trying to just test a simple web service, but can't reach the url I want, i get a 404 error. I'm working on Intellij with Tomcat 8.5.4 :
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
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>seb</groupId>
<artifactId>webapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>1.4.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.10.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
application-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/context">
<jpa:repositories base-package="repository" />
<mvc:annotation-driven/>
<context:component-scan base-package="controller" />
</beans:beans>
web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>springrest</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springrest</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Main.java
#SpringBootConfiguration
#EnableJpaRepositories("repository")
public class Main {
public static void main (String[] args) {
SpringApplication.run(Application.class, args);
}
}
StudentController.java
#RestController
public class StudentController {
private final StudentService studentService;
public StudentController(final StudentService studentService) {
this.studentService = studentService;
}
#RequestMapping(value = "/student", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public void getSomeStudent() {
studentService.getSomeStudent();
System.out.println("Hello");
}
}
The url i'm trying to reach is : localhost:8080/webapp/student, but nothing happen, just have a 404 error. I guess i forgot something, but I looked at some tutorials and questions on the web, and can't figure how to fix my project. So if someone got some clues that can help me, that will be very helpful. Thanks by advance.
change #SpringBootConfiguration to #SpringBootApplication it configures following for you
#Configuration tags the class as a source of bean definitions for the application context.
#EnableAutoConfiguration tells Spring Boot to start adding beans based on classpath settings, other beans, and various property
settings. Normally you would add #EnableWebMvc for a Spring MVC app,
but Spring Boot adds it automatically when it sees spring-webmvc on
the classpath. This flags the application as a web application and
activates key behaviors such as setting up
#ComponentScan tells Spring to look for other components, configurations, and services in the the hello package, allowing it to
find the HelloController.
Since you are using spring-boot, add the following dependency,and remove web.xml where spring-boot automatically configures web dispatcher servlet for you
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
or you can still go ahead and configure one if you want.
Based on your initial settings, controller should be located at
http://localhost:8080/student (no 'webapp')
Well I stopped trying to deploy my app on tomcat, i'm just using spring now and i can reach my url. Anyway i will take deeper look at spring docs and tutorials, thanks for the different explications and link.
Use https://start.spring.io/ to create your Spring Boot Application project.
This will generate spring boot maven project for you.
Then add your StudentController there.
and afer that as #jahra specified, you have to trigger URL : http://localhost:8080/student to access your student webservice

Launch Spring web application using Spring Boot

I am trying to launch an existing web application using Spring Boot, without changing my existing application at all and keeping the spring-boot specific stuff in a separate module. I have the following maven structure:
parent
web-app
boot-app
I want to launch the web-app from the boot-app.
My boot module
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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<dependencies>
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Web Application -->
<dependency>
<groupId>my.group.id.</groupId>
<artifactId>web-app</artifactId>
<version>1.0-SNAPSHOT</version>
<classifier>classes</classifier>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.2.5.RELEASE</version>
</plugin>
</plugins>
</build>
</project>
Application.java:
#EnableAutoConfiguration
#ImportResource("classpath:WEB-INF/myApp-servlet.xml")
public class Application extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
My web module
Structure:
src/main/
java/ --> Rest Endpoints etc.
webapp/ --> web resources, only important files shown
WEB-INF/
myApp-servlet.xml
web.xml
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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>web-app</artifactId>
<packaging>war</packaging>
<name>some-name</name>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.5</version>
<configuration>
<attachClasses>true</attachClasses>
</configuration>
</plugin>
</plugins>
</build>
</project>
web.xml:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>My Web App</display-name>
<!-- Servlet Configuration -->
<servlet>
<servlet-name>myApp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>myApp</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
</web-app>
myApp-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="some.corp.name.space"/>
<mvc:annotation-driven />
</beans>
My Problem
When I run Application.java I get the following error:
Caused by: java.io.FileNotFoundException: class path resource [WEB-INF/myApp-servlet.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:329)
... 24 more
From what I can see, this is because the maven-war-plugin only includes classes in the jar it creates and does not include the webapp directory.
My Question
Is there any way for me to achieve this, with or without the maven-war-plugin?
The most important thing for me is to have the boot-app as a separate module.

Resources