i am new to weblogic, struggling to deploy war. I have a spring boot application running on embedded tomcat.I changed main class as follows.
#SpringBootApplication
#Configuration
#ComponentScan("com.fmc.*")
#EnableAutoConfiguration
public class ApplicationBoot extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(
ApplicationBoot.class, args);
}
#Override
protected SpringApplicationBuilder configure(
SpringApplicationBuilder application) {
return application.sources(ApplicationBoot.class);
}
}
i changed packaging as war and excluded the tomcat jars and deployed. But when a submit request, I am getting 404.
I don't see anything in logs in the diagnostics in admin console. Is there aythere place to see the logs. In the weblogic admin console,I can see the application as active and health as ok.
I changed the same application spring web application, it's running successfully, but not spring boot application.
Thanks for your help.
public class ApplicationBoot extends SpringBootServletInitializer implements WebApplicationInitializer
main class has to implement WebApplicationInitializer, thought of useful for some one
Related
I want to create a Java deamon process (MQ processor) which can be run both from the commandline (java -jar ...) but also as WAR inside a JEE Container like Tomcat. It should automatically start once the WebApp starts. This App is not going to have a WebGUI.
It seems that I can use SpringBoot for this. SpringBoot can both create WAR and JAR-files.
My question is: should I use SpringBoot ApplicationRunner for a portable daemon?
What is the best practice/recipe to create a portable (CLI/WebApp) daemon process with SpringBoot?
How does this work under the hood? If I use ApplicationRunner and create a WAR, does SpringBoot create a Servlet of this?
Tx
ApplicationRunner is new in Spring Boot 1.4. It is similar to CommandLineRunner of Spring Boot 1.3. It isn't involved in the wiring up of the Application context as such that interface wouldn't be responsible for creating any Servlets in the WAR deployment. Here is details on deploying your app as a WAR:
http://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html
#SpringBootApplication
public class Application extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
The SpringBootServletInitializer is what will create the servlet.
Now I am not sure how you are setting up the MQ processor but if it is wired up as a bean and has some listener thread for messages on a queue then you don't really need the ApplicationRunner. You would just need to wire up the processor as a bean and have a #PostConstruct annotation on it so that you can start the listener thread. If you don't have control of the annotations on the bean then you can use the ApplicationRunner and have it Autowired with the processor bean. The runner would then start up the listener thread.
I have created a rest api using Spring rest and Spring boot. When I am trying to deploy it on tomcat on linux server, I get following error:
rror during ServletContainerInitializer processing
javax.servlet.ServletException: Failed to instantiate WebApplicationInitializer class at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:160
Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.server.ResourceConfig
I am following exact Spring boot instruction for tomcat. My question is that I am not using anything related to Jersey for my application (apis) then why it is looking for Jersey related code, and how I can fix it.
public class Application extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
}
Contoller code:
#RestController
#RequestMapping("/rest/cmscontent")
public class BatchController {
If you add spring-boot-starter-web into your POM file as dependency,
it will include embedded web container (Tomcat by default) automatically.
Therefore, just execute JAR directly without deploying it to any web container.
I have some experience with EJB and JBoss and know the basics about Webservices, but I'm new to Spring.
So I tried to deploy the example Spring WS project gs-rest-service-complete without any changes. It is running on Spring Boot, but I cannot deploy and access it on an external Tomcat Server.
This is what I did: I installed Spring Tool Suite Version: 3.6.4.RELEASE and
Apache Tomcat 8.0.24 and defined Tomcat as a new Server in Spring Tool Suite.
It seems to work because I can deploy (and access) the example Spring MVC project and I can deploy another (not Spring Example) Webservice on Tomcat.
However I cannot deploy the gs-rest-service-complete project. I changed packaging in pom.xml to 'war', but it didn't help. Any hints what I could do?
Thanks, caduta
Finally I found the answer at the bottom of this site:
https://spring.io/blog/2014/03/07/deploying-spring-boot-applications
I had to do three steps to get it running:
change packaging to war in pom.xml.
comment out the declaration of the spring-boot-maven-plugin in pom.xml.
change the Application class to inherit from SpringBootServletInitializer and override method configure. This is necessary to register the application in tomcat.
Now the Application class looks like this:
package hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
#Configuration
#ComponentScan
#EnableAutoConfiguration
public class Application extends SpringBootServletInitializer {
private static Class<Application> applicationClass = Application.class;
public static void main(String[] args) {
SpringApplication.run(applicationClass, args);
}
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(applicationClass);
}
}
A general question about building a war from a spring boot application and running it in a standalone servlet container. The documentation I've seems seems at odds with examples on Stack Overflow.
The answer here shows the way I read of doing this a couple of months ago. I read this here, but the guide seems to have changed losing the actual example app.
Here the "configure" method references the main spring boot Application.class.
public class WebInitializer extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
}
There are also these posts here and here that show the "configure" method referring to the SpringBootServletInitializer sub class itself.
public class BootStrap extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(BootStrap.class, args);
}
#Override
protected SpringApplicationBuilder configure(
SpringApplicationBuilder application) {
return application.sources(BootStrap.class);
}
}
and also there is a main method.
Also the spring-boot-sample-traditional  example app at https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples, which shows "WAR packaging"
does it differently
public class WebConfig extends WebMvcConfigurerAdapter {.........
I was wondering is there are issues with choosing over these different ways of seemingly achieving the same thing in spring boot? Or do they all work equally as well and are interchangeable?
Having your main application class extend SpringBootServletInitializer (Bootstrap in your question) or using a separate class (WebInitializer in your question) is down to personal taste. My preference is to take the Bootstrap approach but they both work in the same way; pick which ever you prefer.
If you are only going to deploy your application to a standalone servlet container then you don't need a main method. The main method is used if you want to run the application as an executable war (java -jar my-app.war), or you want to be able to run it directly in your IDE, i.e. without having your IDE deploy it to a servlet container.
spring-boot-sample-traditional illustrates the use of web.xml to Bootstrap a Spring Boot application. Generally speaking, this isn't a recommended approach unless you're stuck on a Servlet 2.5 container. The use of WebMvcConfigurerAdapter has nothing to do with WAR packaging. Take a look at its web.xml to see the relevant pieces of configuration.
Use Spring Initializr
http://start.spring.io/
Choose your project type (Gradle or Maven) and Packaging as war.
Add Web as dependency and Generate the project.
This will bootstrap your app with the "correct" way.
My question relates to Spring Boot and how to configure error pages in a production web app running in cloudfoundry.
In the Spring IO Sagan reference application, I noticed in the MvcConfig, the following code:
#Configuration
public static class ErrorConfig implements EmbeddedServletContainerCustomizer {
#Override
public void customize(ConfigurableEmbeddedServletContainer factory) {
factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/404"));
factory.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500"));
}
}
Is this configuration used in the cloud too? If so why is it named: EmbeddedServletContainerCustomizer? If not what is the equivalent for the cloud?
Yes, you can use EmbeddedServletContainerCustomizer when deploying to the cloud. Sagan itself is doing exactly that on CloudFoundry for the spring.io website.
The "embedded" in the name of EmbeddedServletContainerCustomizer refers to the fact that the servlet container is embedded in your application's executable jar file. It's the recommended approach for cloud deployment.