I am new to spring.
My spring application is up and running. but when i am using postman to fetch the data. it is throwing 404 not found error. I checked URL but I am not getting where I am going wrong.
can anyone help me.
here is my API class
#RestController
#RequestMapping(value="/nicetry")
public class NiceAPI {
#Autowired
private NiceService niceService;
#GetMapping(value = "/student")
public ResponseEntity<List<Student>> getDetails(){
List<Student> studentList= niceService.getDetails();
ResponseEntity<List<Student>> response = new ResponseEntity<List<Student>>
(studentList,HttpStatus.OK);
return response;
}
}
Here is the Postman Screen image
Here is the application console
2020-04-01 23:50:24.207 WARN 8400 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view
rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-04-01 23:50:24.704 INFO 8400 --- [ main]
o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService
'applicationTaskExecutor'
2020-04-01 23:50:25.458 INFO 8400 --- [ main]
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 5556
(http) with context path ''
2020-04-01 23:50:25.495 INFO 8400 --- [ main]
com.saif.NiceTry.NiceTryApplication : Started NiceTryApplication in
44.685 seconds (JVM running for 55.867)
2020-04-01 23:52:02.858 INFO 8400 --- [nio-5556-exec-2] o.a.c.c.C.[Tomcat].
[localhost].[/] : Initializing Spring DispatcherServlet
'dispatcherServlet'
2020-04-01 23:52:02.858 INFO 8400 --- [nio-5556-exec-2]
o.s.web.servlet.DispatcherServlet : Initializing Servlet
'dispatcherServlet'
2020-04-01 23:52:03.276 INFO 8400 --- [nio-5556-exec-2]
o.s.web.servlet.DispatcherServlet : Completed initialization in 417 ms
Help Me
With regards to the above postman image, you are using 5556 port. By default, Spring Boot uses the 8080 port number. You can however change the port that you are running in the properties file. In Spring Boot, properties are kept in the application.properties file under the classpath. The application.properties file is located in the src/main/resources directory.
[https://www.tutorialspoint.com/spring_boot/spring_boot_application_properties.htm][1]
[1]: Spring Boot
Related
I am using Spring Boot with IntelliJ Java 8. For some reason the Bean Factory is working on all other teammates computers from Git, except my local computer. I am receiving the following errors. It's like it cannot initialize the Beans. I cleared, invalidated caches, and restarted Intellij. Still no luck. Does anyone know what the issue can be?
2021-09-02 12:26:49.213 INFO 2430 --- [ main] c.k.s.s.c.capture.server.Application : Starting Application using Java 1.8.0_73 on KMAC-15SJGH5 with PID 2430 (/Users/joe/src/charge-capture/service/service-server/target/classes started by joe in /Users/joe/src/charge-capture)
2021-09-02 12:26:49.217 INFO 2430 --- [ main] c.k.s.s.c.capture.server.Application : No active profile set, falling back to default profiles: default
2021-09-02 12:26:51.689 INFO 2430 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2021-09-02 12:26:51.690 INFO 2430 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-09-02 12:26:51.721 INFO 2430 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 16 ms. Found 0 JPA repository interfaces.
2021-09-02 12:26:51.742 INFO 2430 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2021-09-02 12:26:51.744 INFO 2430 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2021-09-02 12:26:51.768 INFO 2430 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 8 ms. Found 0 Redis repository interfaces.
2021-09-02 12:26:52.197 INFO 2430 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=43442f9b-fc6e-3ab1-be0d-b16685f5327e
2021-09-02 12:26:52.554 INFO 2430 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'com.abcd.library.springboot.autoconfigure.config.RedisCacheCon
This program does not have errors on other computers, and so its not a source code problem, more of an environmental issue with my local.
Active profiles does not seem like the issue, as it has a select mechanism here
public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication(Application.class);
String[] profiles = SpringProfilesUtil.readActiveProfiles(Application.class);
if(profiles != null) {
springApplication.setAdditionalProfiles(profiles);
}
springApplication.run(args);
}
I did not locate Maven Window even though the Plugin was installed.
Right Click on the root pom.xml file and select "Add as Maven Project" from the context menu. After this, application should run without Bean errors.
Not sure why it fixed the issue, however could be a small issue with IntelliJ. Either way, it works.
I have created one simple spring boot application and have added 2 dependencies using spring initializers, H2 and JPA.
I have added H2 configuration in application.properties file and then added hoteldata.sql file in resource folder. When i am running the project, spring boot log doesn't show Tomcat is started.
I am expecting below log to be displayed while starting the spring boot application,
main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8081 (http)
2020-12-06 18:16:26.350 INFO [userms,,,] 9144 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-12-06 18:16:26.351 INFO [userms,,,] 9144 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.37]
2020-12-06 18:16:27.085 INFO [userms,,,] 9144 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
but it is not appearing..
When i am hitting the endpoint, http://localhost:8081/h2-console nothing is happening..
Did i miss anything at configuration level ?
Finally, I have solved this problem. Along with H2 and JPA dependency, we need to add 'spring boot starter web' dependency as well .It helps to start inbuilt Tomcat in spring boot application.
I am trying to follow spring.io's websocket tutorial.
Everything worked fine as long as every java file was located in the same package (I managed to have an end-to-end websocket communication).
I tried to extract GreetingController.java and WebSocketConfig.java classes into another package. The app is then not able to communicate via websocket anymore.
The server's console suggests the SimpleBrokerMessageHandler is not started. Here are the logs of the working and non-working versions :
com.example.tutorial.Application : Starting Application on DESKTOP-SOF4KJM with PID 13408
com.example.tutorial.Application : No active profile set, falling back to default profiles: default
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
o.apache.catalina.core.StandardService : Starting service [Tomcat]
org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.24]
o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1485 ms
o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'clientInboundChannelExecutor'
o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'clientOutboundChannelExecutor'
o.s.s.c.ThreadPoolTaskScheduler : Initializing ExecutorService 'messageBrokerTaskScheduler'
o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'brokerChannelExecutor'
o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: class path resource [static/index.html]
o.s.m.s.b.SimpleBrokerMessageHandler : Starting...
o.s.m.s.b.SimpleBrokerMessageHandler : BrokerAvailabilityEvent[available=true, SimpleBrokerMessageHandler [DefaultSubscriptionRegistry[cache[0 destination(s)], registry[0 sessions]]]]
o.s.m.s.b.SimpleBrokerMessageHandler : Started.
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
com.example.tutorial.Application : Started Application in 2.631 seconds (JVM running for 3.04)
com.example.tutorial.Application : Starting Application on DESKTOP-SOF4KJM with PID 2508
com.example.tutorial.Application : No active profile set, falling back to default profiles: default
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
o.apache.catalina.core.StandardService : Starting service [Tomcat]
org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.24]
o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1509 ms
o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: class path resource [static/index.html]
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
com.example.tutorial.Application : Started Application in 2.52 seconds (JVM running for 2.873)
o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
o.s.web.servlet.DispatcherServlet : Completed initialization in 5 ms
How could I make my SpringBoot app aware of this websocket endpoint in another package, knowing that the GreetingController is annotated #Controller and de WebSocketMessageBrokerConfigurer-extending class is annotated #Configuration & #EnableWebSocketMessageBroker ?
You will need to tell the Spring Boot where to look for Spring components outside the main package. You can use #ComponentScan for it:
#SpringBootApplication
#ComponentScan(value = "com.example.package")
public class Example {...}
#SpringBootApplication is annotated with #ComponentScan but it is only valid for subpackages.
I'm trying to run a custom Spring cloud Stream app starter, and getting the following INFO log,
2017-11-14 14:59:24.600 INFO 30300 --- [ main] o.a.kafka.common.utils.AppInfoParser : Kafka version : 0.10.1.1
2017-11-14 14:59:24.600 INFO 30300 --- [ main] o.a.kafka.common.utils.AppInfoParser : Kafka commitId : f10ef2720b03b247
2017-11-14 14:59:24.747 INFO 30300 --- [ main] o.a.k.clients.producer.KafkaProducer : Closing the Kafka producer with timeoutMillis = 30000 ms.
2017-11-14 14:59:24.768 INFO 30300 --- [ main] o.s.integration.channel.DirectChannel : Channel 'websocket-source.output' has 1 subscriber(s).
2017-11-14 14:59:24.773 INFO 30300 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0
2017-11-14 14:59:24.906 INFO 30300 --- [ main] o.s.i.endpoint.EventDrivenConsumer : Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
My problem is my app doesn't work as intended (I can't connect to the websocket server, which this app will bring up) so I expect some clues from the kafka log. May be some missing dependency but I couldn't find one.
Is it an error? How can I debug this?
When you build Spring Boot Web application, you should keep in mind that security is switched on by default - HTTP Basic Authorization
The default user is, err, user.
The generate password you can find in logs. For example:
2017-11-14 11:56:09.756 INFO 7304 --- [ main] b.a.s.AuthenticationManagerConfiguration :
Using default security password: 396c8870-f36e-44a5-aaea-735d5a8e950a
Although you can turn it off as well. For example command line arg:
--security.basic.enabled=false
https://docs.spring.io/spring-boot/docs/1.5.8.RELEASE/reference/htmlsingle/#howto-switch-off-spring-boot-security-configuration
I am learning WebServices using SpringBoot.
I came across this example spring-actuator-service
The console log states the following
2017-04-07 03:04:59.281 INFO 13024 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 9001 (http)
2017-04-07 03:04:59.290 INFO 13024 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0
2017-04-07 03:04:59.548 INFO 13024 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 9000 (http)
2017-04-07 03:04:59.555 INFO 13024 --- [ main] hello.HelloWorldConfiguration : Started HelloWorldConfiguration in 8.274 seconds (JVM running for 9.183)
When I ran the application as a spring boot application and entered the
http://localhost:9001/hello-world
The response that I get on the screen is as below.
{"timestamp":1491514947950,"status":404,"error":"Not Found","message":"No message available","path":"/hello-world"}
can anyone help me understand why am I not getting the response as
{"id":1,"content":"Hello, Stranger!"}
Port 9001 is the actuator endpoint (health metrics and similar). Port 9000 is your application's content, where the HelloWorldController is. As mentioned in the documentation and by #Marc Tarin, use http://localhost:9000/hello-world.