No mapping for DELETE - spring-boot

this is the implementation if the Http Delete method where i'm trying to delete this object
"vente" by it's id, and as seen below the mapping is provided for the DELETE method.
#DeleteMapping(value = ConstantController.VENTE+"/{venteId}")
public ResponseEntity<?> deleteVente(#PathVariable BigInteger venteId){
venteService.deleteVente(venteId);
return new ResponseEntity<Void>(HttpStatus.OK);
}
this is the uri for accessing the the service:
http://localhost:8080/stock-ws/vente/1
this what i get in the server tomcat log when i send the http request with the delete
method:
2021-10-17 22:18:29.258[0;39m [32m INFO[0;39m [35m3848[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.a.c.c.C.[Tomcat].[localhost].[/] [0;39m [2m:[0;39m Initializing Spring DispatcherServlet 'dispatcherServlet'
[2m2021-10-17 22:18:29.258[0;39m [32m INFO[0;39m [35m3848[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Initializing Servlet 'dispatcherServlet'
[2m2021-10-17 22:18:29.262[0;39m [32m INFO[0;39m [35m3848[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Completed initialization in 4 ms
[2m2021-10-17 22:18:29.289[0;39m [33m WARN[0;39m [35m3848[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.servlet.PageNotFound [0;39m [2m:[0;39m No mapping for DELETE /stock-ws/vente/1
couldn't spot the bug any help will be apreciated!

Maybe you can try this;
#RestController
#RequestMapping("/stock-ws/vente")
class TestController(){
#DeleteMapping("{venteId}")
public ResponseEntity<?> deleteVente(#PathVariable BigInteger venteId){
venteService.deleteVente(venteId);
return new ResponseEntity<Void>(HttpStatus.OK);
}
}

Related

How to resolve "Whitelabel Error Page . There was an unexpected error (type=Not Found, status=404)."

I have a simple project to run on tomcat server, Here it goes
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 https://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>3.0.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.apprikart</groupId>
<artifactId>Temp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Temp</name>
<description>Tempraury</description>
<properties>
<java.version>17</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-web-services</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>10.1.4</version>
</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>
Here is my main class
package com.apprikart;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class TempApplication {
public static void main(String[] args) {
SpringApplication.run(TempApplication.class, args);
}
}
Controller class
package com.apprikart.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
public class AppContrl {
#RequestMapping("/")
public String fun() {
System.out.println("enter");
return "home.jsp";
}
}
application.properties
spring.mvc.view.prefix=/webapp/
Console:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
[32m :: Spring Boot :: [39m [2m (v3.0.1)[0;39m
[2m2023-01-02T17:06:59.336+05:30[0;39m [32m INFO[0;39m [35m7336[0;39m [2m---[0;39m [2m[ main][0;39m [36mcom.apprikart.TempApplication [0;39m [2m:[0;39m Starting TempApplication using Java 17.0.4.1 with PID 7336 (C:\Users\HI\Documents\workspace-spring-tool-suite-4-4.16.1.RELEASE\Temp\target\classes started by HI in C:\Users\HI\Documents\workspace-spring-tool-suite-4-4.16.1.RELEASE\Temp)
[2m2023-01-02T17:06:59.342+05:30[0;39m [32m INFO[0;39m [35m7336[0;39m [2m---[0;39m [2m[ main][0;39m [36mcom.apprikart.TempApplication [0;39m [2m:[0;39m No active profile set, falling back to 1 default profile: "default"
[2m2023-01-02T17:07:00.262+05:30[0;39m [32m INFO[0;39m [35m7336[0;39m [2m---[0;39m [2m[ main][0;39m [36mtrationDelegate$BeanPostProcessorChecker[0;39m [2m:[0;39m Bean 'org.springframework.ws.config.annotation.DelegatingWsConfiguration' of type [org.springframework.ws.config.annotation.DelegatingWsConfiguration$$SpringCGLIB$$0] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
[2m2023-01-02T17:07:00.326+05:30[0;39m [32m INFO[0;39m [35m7336[0;39m [2m---[0;39m [2m[ main][0;39m [36m.w.s.a.s.AnnotationActionEndpointMapping[0;39m [2m:[0;39m Supporting [WS-Addressing August 2004, WS-Addressing 1.0]
[2m2023-01-02T17:07:00.650+05:30[0;39m [32m INFO[0;39m [35m7336[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.b.w.embedded.tomcat.TomcatWebServer [0;39m [2m:[0;39m Tomcat initialized with port(s): 8080 (http)
[2m2023-01-02T17:07:00.668+05:30[0;39m [32m INFO[0;39m [35m7336[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.apache.catalina.core.StandardService [0;39m [2m:[0;39m Starting service [Tomcat]
[2m2023-01-02T17:07:00.668+05:30[0;39m [32m INFO[0;39m [35m7336[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.apache.catalina.core.StandardEngine [0;39m [2m:[0;39m Starting Servlet engine: [Apache Tomcat/10.1.4]
[2m2023-01-02T17:07:00.930+05:30[0;39m [32m INFO[0;39m [35m7336[0;39m [2m---[0;39m [2m[ main][0;39m [36morg.apache.jasper.servlet.TldScanner [0;39m [2m:[0;39m At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
[2m2023-01-02T17:07:00.941+05:30[0;39m [32m INFO[0;39m [35m7336[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.a.c.c.C.[Tomcat].[localhost].[/] [0;39m [2m:[0;39m Initializing Spring embedded WebApplicationContext
[2m2023-01-02T17:07:00.942+05:30[0;39m [32m INFO[0;39m [35m7336[0;39m [2m---[0;39m [2m[ main][0;39m [36mw.s.c.ServletWebServerApplicationContext[0;39m [2m:[0;39m Root WebApplicationContext: initialization completed in 1493 ms
[2m2023-01-02T17:07:01.442+05:30[0;39m [32m INFO[0;39m [35m7336[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.b.w.embedded.tomcat.TomcatWebServer [0;39m [2m:[0;39m Tomcat started on port(s): 8080 (http) with context path ''
[2m2023-01-02T17:07:01.456+05:30[0;39m [32m INFO[0;39m [35m7336[0;39m [2m---[0;39m [2m[ main][0;39m [36mcom.apprikart.TempApplication [0;39m [2m:[0;39m Started TempApplication in 2.802 seconds (process running for 4.043)
[2m2023-01-02T17:07:06.866+05:30[0;39m [32m INFO[0;39m [35m7336[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36mo.a.c.c.C.[Tomcat].[localhost].[/] [0;39m [2m:[0;39m Initializing Spring DispatcherServlet 'dispatcherServlet'
[2m2023-01-02T17:07:06.866+05:30[0;39m [32m INFO[0;39m [35m7336[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Initializing Servlet 'dispatcherServlet'
[2m2023-01-02T17:07:06.867+05:30[0;39m [32m INFO[0;39m [35m7336[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Completed initialization in 1 ms
enter
Hierarchy
enter image description here
Please help me resolve the issue, I'm unable to trace where I'm going wrong.
I have tried almost everything suggested in the internet

Unknown column in 'field list' in cascading persistance

I am using Spring Boot Version 2.5.2 , spring data jpa and MySQL Database
CREATE TABLE Timesheet (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`tsYear` VARCHAR(4) NOT NULL,
`weekNumber` INT NOT NULL,
`startDate` DATE NOT NULL,
`endDate` DATE NOT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE TimesheetDays (
`id` INT NOT NULL AUTO_INCREMENT,
`timesheetId` BIGINT(20) NOT NULL,
`dayNumber` INT NOT NULL,
`dayDate` DATE NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `tsdTimesheetId`
FOREIGN KEY (`timesheetId`)
REFERENCES Timesheet (`id`)
);
#Entity
#Table(name = "timesheet")
public class Timesheet {
#Id
#Column(name = "id")
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
#OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE }, mappedBy = "timesheet")
private List<TimesheetDay> days = null;
}
#Entity
#Table(name = "timesheetdays")
public class TimesheetDay {
#Id
#Column(name = "id")
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
#ManyToOne
private Timesheet timesheet;
}
When i tried to save (timesheet and timesheetdays), for timesheetdays table, hibernate is
generating wrong column.
[2m2021-11-05 18:29:44.147[0;39m [32mDEBUG[0;39m [35m15036[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36morg.hibernate.SQL [0;39m [2m:[0;39m insert into timesheetdays (daydate, daynumber, timesheet_id) values (?, ?, ?)
[2m2021-11-05 18:29:44.147[0;39m [32mTRACE[0;39m [35m15036[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36mo.h.type.descriptor.sql.BasicBinder [0;39m [2m:[0;39m binding parameter [1] as [DATE] - [2017-12-20]
[2m2021-11-05 18:29:44.148[0;39m [32mTRACE[0;39m [35m15036[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36mo.h.type.descriptor.sql.BasicBinder [0;39m [2m:[0;39m binding parameter [2] as [INTEGER] - [1]
[2m2021-11-05 18:29:44.148[0;39m [32mTRACE[0;39m [35m15036[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36mo.h.type.descriptor.sql.BasicBinder [0;39m [2m:[0;39m binding parameter [3] as [INTEGER] - [18]
[2m2021-11-05 18:29:44.148[0;39m [33m WARN[0;39m [35m15036[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36mo.h.engine.jdbc.spi.SqlExceptionHelper [0;39m [2m:[0;39m SQL Error: 1054, SQLState: 42S22
[2m2021-11-05 18:29:44.148[0;39m [31mERROR[0;39m [35m15036[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36mo.h.engine.jdbc.spi.SqlExceptionHelper [0;39m [2m:[0;39m Unknown column 'timesheet_id' in 'field list'
Since the generated column name is timesheet_id, it is not working.
If the generated column name becomes timesheetid, it will work.
Please help to resolve this issue
You need to add the #JoinColumn annotation to give the column name value specifically in your TimesheetDay entity.
#ManyToOne
#JoinColumn(name="timesheetid")
private Timesheet timesheet;

Restriction for localhost is not working in SpringBoot web security

Restriction for localhost is not working in SpringBoot web security.By commenting the configure method content, URL(http://127.0.0.1:8080/SPPA/runSPPAJob) is working otherwise error comes.
Code:
#EnableWebSecurity
#Configuration
public class AllowOnlyLocalhostFilter extends WebSecurityConfigurerAdapter
{
#Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/SPPA/**").
access("hasIpAddress('127.0.0.1')").anyRequest().authenticated();
}
}
Web Page Response:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon May 29 16:05:46 IST 2017
There was an unexpected error (type=Forbidden, status=403).
Access Denied
Log:
2017-05-29 16:05:46.482 INFO 3644 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/SPPA] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2017-05-29 16:05:46.482 [http-nio-8080-exec-1] INFO
o.a.c.c.C.[.[localhost].[/SPPA]-Initializing Spring FrameworkServlet 'dispatcherServlet'
2017-05-29 16:05:46.485 INFO 3644 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2017-05-29 16:05:46.485 [http-nio-8080-exec-1] INFO
o.s.web.servlet.DispatcherServlet-FrameworkServlet 'dispatcherServlet': initialization started
2017-05-29 16:05:46.684 INFO 3644 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 199 ms
2017-05-29 16:05:46.684 [http-nio-8080-exec-1] INFO
o.s.web.servlet.DispatcherServlet-FrameworkServlet 'dispatcherServlet': initialization completed in 199 ms

Spring Security OAuth2 always redirects to /login page having a valid Bearer header

I am having a hard time getting Spring Security OAuth2 to work. I am able to get a access_token from /oauth/token endpoint but accessing a protected resource with that token in header "Authorization: Bearer $TOKEN" always redirects me to /login. This is a complete REST API.
OAuth2Config
#Configuration
public class OAuth2Configuration {
private static final String SERVER_RESOURCE_ID = "oauth2-server";
private static InMemoryTokenStore tokenStore = new InMemoryTokenStore();
#Configuration
#EnableResourceServer
protected static class ResourceServer extends ResourceServerConfigurerAdapter {
#Override
public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
resources.tokenStore(tokenStore).resourceId(SERVER_RESOURCE_ID);
}
#Override
public void configure(HttpSecurity http) throws Exception {
http.requestMatchers().antMatchers("/admin**").and().authorizeRequests().antMatchers("/admin**").access("#oauth2.hasScope('read')");
}
}
#Configuration
#EnableAuthorizationServer
protected static class AuthConfig extends AuthorizationServerConfigurerAdapter {
#Autowired
private AuthenticationManager authenticationManager;
#Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.authenticationManager(authenticationManager).tokenStore(tokenStore).approvalStoreDisabled();
}
#Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("my-client")
.authorizedGrantTypes("authorization_code","refresh_token", "password")
.authorities("ROLE_CLIENT")
.scopes("read")
.resourceIds(SERVER_RESOURCE_ID)
.secret("secret")
;
}
}
}
SecurityConfig class
#Configuration
#EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
#Autowired
private UserDetailsService userDetailsService;
#Bean
public BCryptPasswordEncoder bCryptPasswordEncoder() {
return new BCryptPasswordEncoder();
}
#Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.userDetailsService(userDetailsService)
.passwordEncoder(bCryptPasswordEncoder());
}
#Override
#Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
}
Following are the debug logs
2017-04-10 10:58:31.634[0;39m [32mDEBUG[0;39m [35m6456[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Initializing servlet 'dispatcherServlet'
[2m2017-04-10 10:58:31.635[0;39m [32m INFO[0;39m [35m6456[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.a.c.c.C.[Tomcat].[localhost].[/] [0;39m [2m:[0;39m Initializing Spring FrameworkServlet 'dispatcherServlet'
[2m2017-04-10 10:58:31.635[0;39m [32m INFO[0;39m [35m6456[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m FrameworkServlet 'dispatcherServlet': initialization started
[2m2017-04-10 10:58:31.635[0;39m [32mDEBUG[0;39m [35m6456[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Using MultipartResolver [org.springframework.web.multipart.support.StandardServletMultipartResolver#40aad17d]
[2m2017-04-10 10:58:31.639[0;39m [32mDEBUG[0;39m [35m6456[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Unable to locate LocaleResolver with name 'localeResolver': using default [org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver#70f4e8c6]
[2m2017-04-10 10:58:31.643[0;39m [32mDEBUG[0;39m [35m6456[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Unable to locate ThemeResolver with name 'themeResolver': using default [org.springframework.web.servlet.theme.FixedThemeResolver#201a4016]
[2m2017-04-10 10:58:31.649[0;39m [32mDEBUG[0;39m [35m6456[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Unable to locate RequestToViewNameTranslator with name 'viewNameTranslator': using default [org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator#5f14eeee]
[2m2017-04-10 10:58:31.656[0;39m [32mDEBUG[0;39m [35m6456[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Unable to locate FlashMapManager with name 'flashMapManager': using default [org.springframework.web.servlet.support.SessionFlashMapManager#1688575]
[2m2017-04-10 10:58:31.656[0;39m [32mDEBUG[0;39m [35m6456[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Published WebApplicationContext of servlet 'dispatcherServlet' as ServletContext attribute with name [org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcherServlet]
[2m2017-04-10 10:58:31.656[0;39m [32m INFO[0;39m [35m6456[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m FrameworkServlet 'dispatcherServlet': initialization completed in 21 ms
[2m2017-04-10 10:58:31.656[0;39m [32mDEBUG[0;39m [35m6456[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Servlet 'dispatcherServlet' configured successfully
[2m2017-04-10 10:58:31.692[0;39m [32mDEBUG[0;39m [35m6456[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m DispatcherServlet with name 'dispatcherServlet' processing POST request for [/oauth/token]
[2m2017-04-10 10:58:31.695[0;39m [32mDEBUG[0;39m [35m6456[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36ms.w.s.m.m.a.RequestMappingHandlerMapping[0;39m [2m:[0;39m Looking up handler method for path /oauth/token
[2m2017-04-10 10:58:31.699[0;39m [32mDEBUG[0;39m [35m6456[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36ms.w.s.m.m.a.RequestMappingHandlerMapping[0;39m [2m:[0;39m Did not find handler method for [/oauth/token]
[2m2017-04-10 10:58:32.012[0;39m [32m INFO[0;39m [35m6456[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.o.p.token.store.JdbcTokenStore [0;39m [2m:[0;39m Failed to find access token for token 7c74f287-e187-4228-b0c2-b79972f9b89b
[2m2017-04-10 10:58:32.226[0;39m [32mDEBUG[0;39m [35m6456[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.w.s.m.m.a.HttpEntityMethodProcessor [0;39m [2m:[0;39m Written [7c74f287-e187-4228-b0c2-b79972f9b89b] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter#2fd4312a]
[2m2017-04-10 10:58:32.226[0;39m [32mDEBUG[0;39m [35m6456[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
[2m2017-04-10 10:58:32.226[0;39m [32mDEBUG[0;39m [35m6456[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Successfully completed request
What is it that I am missing? I have almost tried every example over the web into my existing project but I am always redirected to the /login endpoint when I try to request a protected resource with a valid token.
Thanks.
So it turned out that since I was upgrading from an earlier version of spring boot to 1.5.2, in the release notes it is said that the order of the resource filter has been changed. See here. Just place this magic property in application.properties file and it fixes everything.
security.oauth2.resource.filter-order = 3
he default order of the OAuth2 resource filter has changed from 3 to SecurityProperties.ACCESS_OVERRIDE_ORDER - 1. This places it after the actuator endpoints but before the basic authentication filter chain. The default can be restored by setting security.oauth2.resource.filter-order = 3.

Unable to load Jsp page using Spring Boot 1.4.3 Release Version and Spring 4.3.5.RELEASE version

I am new in the Spring Boot Application development.I am doing simple spring boot application using spring boot version 1.4.3 Release version and Spring 4.3.5.RELEASE version. I am successfully in the configuration of Mysql database configuration. Also table get created while running Spring Boot main class.
Below is Spring Boot project directory structure :
SpringBootApp[boot]
src/main/java
-config
-controller
-dto
-entity
-repository
-service
src/main/resources
-application.properties
src/test/java
src/main/webapp
/recources/css
/resources/images
/resources/js
/WEB-INF/view/jsp/main.jsp
I created DBConfig.java file which having DB related functionality like datasource creation,jpa transaction management.
Below is WebMVC configuration file:
#EnableWebMvc
#Configuration
#Import(DBConfig.class)
#ComponentScan(basePackages = { "com.tms" })
public class SpringWebConfig extends WebMvcConfigurerAdapter {
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
#Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/view/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
#Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}
Below is App Context initializer file :
public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
#Override
protected Class<?>[] getRootConfigClasses() {
return new Class[] { DBConfig.class };
}
#Override
protected Class<?>[] getServletConfigClasses() {
return new Class[] { SpringWebConfig.class };
}
#Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
}
I also added below line of code in application.properties file to locate jsp pages and to deactivate thymeleaf template.
spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp
spring.thymeleaf.check-template-location=false
Below is Spring Controller java file:
#RequestMapping("/")
public class IndexController {
#RequestMapping(method = RequestMethod.GET)
public String printWelcome(ModelMap model) {
model.addAttribute("title", "Hello world!");
return "main";
}
}
Below jsp sample page :
/WEB-INF/jsp/main.jsp
<%#taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<html>
<head>
<title>Spring Boot</title>
</head>
<body>
<h2>Test Page</h2>
<table>
<tr>
<td>Title</td>
<td>${title}</td>
</tr>
</table>
</body>
</html>
Spring Boot Application successfully get started.
Below is STS console output :
2017-01-12 04:22:57.501[0;39m [32m INFO[0;39m [35m4968[0;39m [2m---[0;39m [2m[ main][0;39m [36morg.hibernate.tool.hbm2ddl.SchemaUpdate [0;39m [2m:[0;39m HHH000228: Running hbm2ddl schema update
[2m2017-01-12 04:22:57.677[0;39m [32m INFO[0;39m [35m4968[0;39m [2m---[0;39m [2m[ main][0;39m [36mj.LocalContainerEntityManagerFactoryBean[0;39m [2m:[0;39m Initialized JPA EntityManagerFactory for persistence unit 'jpaUnit'
[2m2017-01-12 04:22:58.392[0;39m [32m INFO[0;39m [35m4968[0;39m [2m---[0;39m [2m[ main][0;39m [36ms.w.s.m.m.a.RequestMappingHandlerMapping[0;39m [2m:[0;39m Mapped "{[/book]}" onto public org.springframework.http.ResponseEntity<java.util.List<com.tms.dto.BookDto>> com.tms.controller.BookController.getAllBooks()
[2m2017-01-12 04:22:58.400[0;39m [32m INFO[0;39m [35m4968[0;39m [2m---[0;39m [2m[ main][0;39m [36ms.w.s.m.m.a.RequestMappingHandlerMapping[0;39m [2m:[0;39m Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
[2m2017-01-12 04:22:58.401[0;39m [32m INFO[0;39m [35m4968[0;39m [2m---[0;39m [2m[ main][0;39m [36ms.w.s.m.m.a.RequestMappingHandlerMapping[0;39m [2m:[0;39m Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
[2m2017-01-12 04:22:58.466[0;39m [32m INFO[0;39m [35m4968[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.w.s.handler.SimpleUrlHandlerMapping [0;39m [2m:[0;39m Mapped URL path [/resources/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
[2m2017-01-12 04:22:58.476[0;39m [32m INFO[0;39m [35m4968[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.w.s.handler.SimpleUrlHandlerMapping [0;39m [2m:[0;39m Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler]
[2m2017-01-12 04:22:58.596[0;39m [32m INFO[0;39m [35m4968[0;39m [2m---[0;39m [2m[ main][0;39m [36ms.w.s.m.m.a.RequestMappingHandlerAdapter[0;39m [2m:[0;39m Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#33d512c1: startup date [Thu Jan 12 04:22:49 IST 2017]; root of context hierarchy
[2m2017-01-12 04:23:00.111[0;39m [32m INFO[0;39m [35m4968[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.j.e.a.AnnotationMBeanExporter [0;39m [2m:[0;39m Registering beans for JMX exposure on startup
[2m2017-01-12 04:23:00.265[0;39m [32m INFO[0;39m [35m4968[0;39m [2m---[0;39m [2m[ main][0;39m [36ms.b.c.e.t.TomcatEmbeddedServletContainer[0;39m [2m:[0;39m Tomcat started on port(s): 8080 (http)
[2m2017-01-12 04:23:00.276[0;39m [32m INFO[0;39m [35m4968[0;39m [2m---[0;39m [2m[ main][0;39m [36mcom.tms.config.App [0;39m [2m:[0;39m Started App in 12.241 seconds (JVM running for 13.221)
[2m2017-01-12 04:23:01.999[0;39m [32m INFO[0;39m [35m4968[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.a.c.c.C.[Tomcat].[localhost].[/] [0;39m [2m:[0;39m Initializing Spring FrameworkServlet 'dispatcherServlet'
[2m2017-01-12 04:23:02.000[0;39m [32m INFO[0;39m [35m4968[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m FrameworkServlet 'dispatcherServlet': initialization started
[2m2017-01-12 04:23:02.040[0;39m [32m INFO[0;39m [35m4968[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m FrameworkServlet 'dispatcherServlet': initialization completed in 40 ms
When i type url http://localhost:8080/ in the browser it will give below message :
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu Jan 12 04:24:27 IST 2017
There was an unexpected error (type=Not Found, status=404).
Also i tried http://localhost:8080/SpringBootApp/ url in the browserit will show below message :
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu Jan 12 04:33:26 IST 2017
There was an unexpected error (type=Not Found, status=404).
/SpringBootApp/
No any error message printed in the STS console.
I would be thankful if anybody have solution/ to suggest other approach for the same.
Your views are in /view/jsp/, but your view resolver only says /view/. Also it seems wrong to have the configuration in both application.properties, and code.
And personally I would use Thymeleaf for server side rendering these days.
Change
viewResolver.setPrefix("/WEB-INF/view/");
to
viewResolver.setPrefix("/WEB-INF/view/jsp/");

Resources