spring-mvc

Spring security 401 Unauthorized even with permitAll

泪湿孤枕 提交于 2020-05-13 13:12:02
问题 I'm using Spring security to secure some endpoints in my REST service. here's the security configuration class: @Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(securedEnabled = true, jsr250Enabled = true, prePostEnabled = true) public class SecurityConfig extends WebSecurityConfigurerAdapter { // Other methods @Override protected void configure(HttpSecurity http) throws Exception { http .cors() .and() .csrf() .disable() .exceptionHandling() .authenticationEntryPoint(this

Generate swagger JSON file at compile time for springfox based project

拜拜、爱过 提交于 2020-05-13 05:07:16
问题 I have working project which is using springfox to generate API documentations. I want to generate swagger.json at compile time . following is sample springfox configuration, @Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket productApi() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.basePackage("com.abc.xyz")) .paths(regex("/*.*")) .build(); } } FYI : I have also tried https://github.com/kongchen/swagger-maven-plugin

how to get returned value of my controllers from HandlerInterceptor

元气小坏坏 提交于 2020-05-13 04:34:22
问题 I'm creating a log manager for my controllers that logs every action in it and returned values My controllers are defined in this way: @Controller @RequestMapping(value="/ajax/user") public class UserController extends AbstractController{ @RequestMapping(value="/signup") public @ResponseBody ActionResponse signup(@Valid SignupModel sign) { ActionResponse response=new ActionRespone(); response.setMessage("This is a test message"); return response; } } and I defined a HandlerInterceptor to log

Status expected:<200> but was:<404> in spring test

允我心安 提交于 2020-05-11 04:04:30
问题 I have this class: package controllers; import static org.junit.Assert.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.util.HashSet; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.springframework.beans.factory.annotation

Status expected:<200> but was:<404> in spring test

白昼怎懂夜的黑 提交于 2020-05-11 04:03:49
问题 I have this class: package controllers; import static org.junit.Assert.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.util.HashSet; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.springframework.beans.factory.annotation

Why I received an Error 403 with MockMvc and JUnit?

大城市里の小女人 提交于 2020-05-09 19:00:31
问题 I have a spring mvc (3.2.5) application with spring security (3.2). I configured my SecurityConfig.class with this method : @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests().antMatchers("/*").permitAll().and() .formLogin().successHandler(successHandler) .defaultSuccessUrl("/") .failureHandler(failureHandler).failureUrl("/login?error=true") .permitAll().and().logout() .permitAll(); http.authorizeRequests().antMatchers("/resources/**").permitAll()

passing different types of arguments to jdbctemplate query

[亡魂溺海] 提交于 2020-05-09 01:26:42
问题 I am trying to retrieve records from the database by using where clause with few different types of arguments. This is the simple method which I wrote where I am passing breedId and gender as an arguments. public List<Dog> listByBreedIdAndGender(long breedId, String gender) { return query("SELECT * FROM dog_entity WHERE breed__id = ? AND gender = ?", new MapSqlParameterSource(":breedId", breedId) .addValue(":gender", gender)); } private List<Dog> query(String sql, MapSqlParameterSource

passing different types of arguments to jdbctemplate query

谁说我不能喝 提交于 2020-05-09 01:24:08
问题 I am trying to retrieve records from the database by using where clause with few different types of arguments. This is the simple method which I wrote where I am passing breedId and gender as an arguments. public List<Dog> listByBreedIdAndGender(long breedId, String gender) { return query("SELECT * FROM dog_entity WHERE breed__id = ? AND gender = ?", new MapSqlParameterSource(":breedId", breedId) .addValue(":gender", gender)); } private List<Dog> query(String sql, MapSqlParameterSource

How to serve static resources using Spring's mvc:resources on WebLogic?

会有一股神秘感。 提交于 2020-04-30 12:20:12
问题 We have a web app that works beautifully on tomcat, but fails to run on a latest weblogic cause of static resource loading issues - basically we serve all resources from /static/** and have set this up in the spring servlet xml file like this: <mvc:resources mapping="/static/**" location="/static/" /> This works on tomcat, but on weblogic you simply see an ugly page as all CSS/JS/jpgs within the static directoty cannot be found. I played with this, too: <mvc:default-servlet-handler /> I

How to serve static resources using Spring's mvc:resources on WebLogic?

白昼怎懂夜的黑 提交于 2020-04-30 12:18:32
问题 We have a web app that works beautifully on tomcat, but fails to run on a latest weblogic cause of static resource loading issues - basically we serve all resources from /static/** and have set this up in the spring servlet xml file like this: <mvc:resources mapping="/static/**" location="/static/" /> This works on tomcat, but on weblogic you simply see an ugly page as all CSS/JS/jpgs within the static directoty cannot be found. I played with this, too: <mvc:default-servlet-handler /> I