Piotr Chabros
Piotr Chabros

Reputation: 63

Dynamic Web Application - platform with components

I am doing a research on how to make a proper structure for my web application. It will be a web application serving as a platform for additional, independent components. The components must be able to map requests by using the @Controller annotaion.

So far I have learned, that:

The platform will be deployed as a .war file on Tomcat. The platform classpath location will contain components in a form of .jar files.

My question is:

So far I have the platform.war running on Tomcat. It is annotation based Spring configuration.

I also have the first component, it is a single Java class with @Controller annotation and first mapping. For some reason when I include this component in the classpath of the platform and try to access the url mapped in the component, the application returns 404 error. In the log files it says "No mapping found for HTTP request" so it does not initialize the component's @Controller.

For further explanation click here.

Upvotes: 3

Views: 68

Answers (1)

Stefan
Stefan

Reputation: 12453

In your JAR file, create a package defining your namespace, i.e: "com.platformproject.web". Then all you need to do is put the JAR file in WEB-INF/lib (or better use Maven Modules) and scan the annotations at startup:

MvcConfig.java

@EnableWebMvc
@Configuration
@ComponentScan(basePackages = { "com.platformproject.web" })
public class MvcConfig extends WebMvcConfigurerAdapter { ... }

Upvotes: 1

Related Questions