Building a new project downloaded using https://start.spring.io/ does not run on browser.
I have seen some solutions on stackoverflow which require to make some changes or add, but default/out-of-the-box application does not run.
I asked this in Github https://github.com/spring-projects/spring-boot/issues/20603 but was told that i need to add request mappings or something else. There's no default mapping for the root. That's indeed the default error page showing you a 404.
Is there a documentation to "add request mappings or something else" ? It will help if the application run showing some text instead of an error message. This maybe a simple obvious thing for Spring developers but for learners, takes a lot of effort.
http://localhost:8080/
STEPS TO REPRODUCE:
Download new project at https://start.spring.io/
mvn clean package
mvn spring-boot:run
That is the expected behavior right after creating a fresh Spring Boot project. The initializer does not register any endpoint for you, it just gives you the project skeleton you can start working with.
If you want to see something on localhost:8080/ consider adding the following Java class to your project:
#RestController
public class HelloWorldController {
#GetMapping
public String helloWorld() {
return "Hello World!";
}
}
If you are new to Spring/Spring Boot, I can recommend the following resources:
Official Spring Web documentation
Spring Boot Guides
Developing a CRUD API with Spring Boot YouTube course
Related
I am new to FF4J and started with hello world application.
I wrote a sample spring boot project and added dependency for ff4j-spring-boot-starter and ff4j-web modules in my pom.xml.
However, when I run the application, the FF4J web console is displayed distracted.
Below is my pom.xml and web console screenshot.
Below is the web console that I see
I am not sure what is the mistake here.
Please check and help. Thanks.
Please add "/" at end of the URL in browser. So if, the ff4j-console url is http://localhost:8080/ff4j-console it should be changed to http://localhost:8080/ff4j-console/
This resolved my problem.
I imported on of the Spring Boot getting started projects,
gs-rest-service-complete and looked over it, ran it and got the
general idea how I could start things. So needless to say, I started
to modify that project in order to get my own set of web services
started. Originally there was an Application class in the hello
package annotated with the #SpringBootApplication and had a main
method which did a SpringApplication.run(Application.class, args) to
get it running. Obviously I was going to use the 'hello' package, so
I deleted all that and made my own package hierarchy something on the
order of com.mycompany.product. In that package I made an
Application.class with the same guts (but corresponding to this
package) and a controller in a subpackage of that.
When trying to start the spring boot app, i get this error in the console now:
Error: Could not find or load main class hello.Application
I have no idea what's telling it to look for that specific class in
that specific package. There's no reference to that stuff in my
project anymore. (running in STS).
What controls this? What do I do? I had assumed having only class in
the project at the top of a package layout with the
#SpringBootApplication would get everything moving 'just right'.
How about that... The Boot Dashboard is actually a bunch of launch configurations for run or debug.
I selected my app there and realized when right clicking on it there was an option called "Open Config" which brought me to the "Debug Configurations" dialog. And there was my answer... in the "Main type" field, it said "hello.Application". That's where you set or change it.
I changed that to my "com.mycompany.product.Application" and the app started up as hoped!
The recommended way to get started with a spring boot application is to use the initializr
Click on the 'Switch to full version', fill in the details of your application and select the spring-boot starter packages you want to include. You can look in the pom.xml of the demo project you were using as a tutorial to figure out which ones you need. Then you just click the generate project button and import it into eclipse. Inside eclipse go file -> import -> Maven -> Existing maven projects. Then point to where you unzipped the file you downloaded from spring initializr and it will import your project into Eclipse.
I created a simple app using Spring boot and the spring cloud starter hystrix library.
In my build.gradle:
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.cloud:spring-cloud-starter-hystrix-dashboard:1.0.0.RC2")
compile("org.springframework.cloud:spring-cloud-starter-hystrix:1.0.0.RC2")
}
I deployed one app as a hystrix dashboard using the above libraries and #EnableHystrixDashboard
I then deployed another app which was annotated with #EnableHystrix
I added a component that has a command that I invoke through a controller, just to test things out:
#HystrixCommand(fallbackMethod = "onFailedToSayHello")
public String sayHello(Map<String, String> parameters) {
if (parameters.get("fail") != null && parameters.get("fail").equals("yes")) {
throw new RuntimeException("I failed because you told me to");
}
return "Hello";
}
private String onFailedToSayHello(Map<String, String> parameters) {
return "Bye";
}
The hystrix app runs fine. When I hit the URL I see the stream, the ouptut of which I put in a gist here.
I just see that repeating over and over.
My dashboard is up and running and when I enter the URL of my running hystrix sample app I get a loading screen:
Then, when I check my hystrix app again I see this:
λ curl http://myappurl/hystrix.stream
{"timestamp":1423748238280,"status":503,"error":"Service Unavailable","message":"MaxConcurrentConnections reached: 5","path":"/hystrix.stream"}
I am not sure where to go from here. I tried deploying the hystrix dashboard war instead of building it myself which I downloaded from here but got the same result.
I also noticed some JavaScript error outputs in the browser console which I put here in case they are any use.
And in the server logs I see this repeated over and over:
2015-02-15 20:03:55.324 INFO 9360 --- [nio-8080-exec-9]
ashboardConfiguration$ProxyStreamServlet :
Proxy opening connection to: http://myappurl/hystrix.stream
I am now going to try and get turbine running and see if using that somehow magically fixes things. Thought I would post here too though on the off chance someone can spot an error on my part based on what I've done so far.
EDIT:
An important point I didn't mention is that I have both the app and the dashboard deployed on PCF. This seems to be important since this issue doesn't happen when I deploy locally. Still no idea what's causing it though.
Problem goes away if you build hystrix-dashboard from the latest source, or use the most recently released war (version 1.4.3 on 27th March at time of writing).
Several things can probably lead to MaxConcurrentConnections, and one of them is no any metrics data generated by the application. The servlets (Hystrix.stream servlets) will keep looping to wait data, then it will consumes all the connections. There are very good discussion on the Hystrix github wiki. For example:
hystrix.stream holds connection open if no metrics #85
I have created a Dynamic web project which also uses drools for providing some functionality. When i put the WAR file in Tomcat7 and the server, the drools part does not work.
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
After this line which is first line relating to drools, nothing happens.
Is some configuration required to run my project containing drools 5.5.0 Final in the Tomcat7.
Please help me. I am badly stuck and I am new to drools.
You'll have to add some facts to the working memory and execute(fire) the rules. Check out these examples on GitHub
P.S. Probably not related to Tomcat in any way. Might be worth while to try getting the rules executed from command line app first.
You need to check all the dependencies that are added to your web application (WEB-INF/lib) make sure that drools has all the required deps there, because if not it will not be able to create the knowledge builder. Most of the time if it is failing is because that you forgot to add the deps in the web app.
The following project in GitHub is a web application, containing some REST-style endpoints for validating IBANs. It uses Drools 5.5 to perform that evaluation.
https://github.com/gratiartis/sctrcd-payment-validation-web/
It generates a .war which can be loaded into Tomcat, and could be a useful starting point. The knowledge base is wrapped within a Spring service:
https://github.com/gratiartis/sctrcd-payment-validation-web/blob/master/src/main/java/com/sctrcd/payments/validation/RuleBasedIbanValidator.java
Following through how that creates a knowledge base and session might help you see where your code is going wrong.
As a bonus, you can run it up in Tomcat using "mvn tomcat7:run" to test it out immediately.
I am trying to build an project in Eclipse (actually I'm using RAD, so basically eclipse, and when I say 'Java EE Project' I mean an 'Enterprise Application Project').
My Enterprise Application Project (the 'EAR' project) has two module projects :
- service
- web
The service project has some stuff in it, all wired up using Spring.
The web project has its own stuff in it, all wired up using Spring. The UI stuff in the web project needs to use the stuff in the service project.
Both projects are included in the EAR project as modules.
The web project lists the 'service' project as a dependent project in the build path, it's checked off for export, and also has it listed as a EE Module Dependency.
I'm having a really hard time to get this working though:
The spring context in the web project is of course what gets loaded when the application is deployed, and it imports the spring config I need from the service project. This seems to be working fine.
When spring tries to instantiate a bean it throws a ClassNotFoundException. On the very first bean.
I tried simply copying the spring config from my service context and pasting it into my web context, but I got the same ClassNotFoundException.
I have tried instantiating an object of that type (the class that spring says cannot be found) in the java controller class in the web project, and it is successful, both at compile time (no compile errors) and at runtime (no exceptions).
So the classes from my service project are not available on the classpath when spring tries to use them.
Any ideas what's going on here and/or what I might be able to do about it?
There is a class loader policy that you should use ParentClass First . That will be managed either through Application.xml or through web.xml . You need to check your xml's then try.
It's a class loader issue.
Since you're using Spring, I'll assume that you don't have EJBs. If that's the case, why do you need an EAR? Deploy the whole thing as a web project, in a single WAR.
Put all your .class and Spring configuration .xml files in WEB-INF/classes. Load the configuration using org.springframework.web.context.ContextLoaderListener.
I seem to have fixed this - I'm not sure exactly what the problem was but there must have been a small typo in my spring config. I decided to just start fresh with a new spring config and when I started building the new one back up things were working fine. There must have been a problem with the old one.
Thanks for the suggestions though.
Unfortunately we're not always able to change project structure. We're working on structures other people have put in place.
I looked into the ParentClassFirst vs ParentClassLast setting - it seems on websphere the ParentClassFirst setting is the default if you don't specify anything, so I'm leaving it without specification to get that functionality.
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/crun_classload.html