我有资源服务器,当它启动时 - 它正在向身份验证服务器发送请求(" http:// localhost:xxxx/auth/oauth/token_key "),并且在所有启动并运行时都可以.
但是当我测试我的服务时,我根本不需要它.如何禁用资源服务器或者我应该模拟一些东西,以便它不依赖于auth服务器(对于控制器的未来安全测试)?
我的春靴主要:
@SpringBootApplication
@EnableEurekaClient
@EnableResourceServer
public class CalendarApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(CalendarApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
application.yml
security:
basic:
enabled: false
oauth2:
resource:
jwt:
keyUri: http://localhost:xxxx/auth/oauth/token_key
Run Code Online (Sandbox Code Playgroud)
测试类注释:
@RunWith(SpringJUnit4ClassRunner.class)
@WebMvcTest(value = TypeController.class, secure = false)
public class TypeControllerTest {}
Run Code Online (Sandbox Code Playgroud) 我在spring应用程序中有这个错误(但是应用程序运行并正常工作):
Could not autowire. There is more than one bean of 'OAuth2ClientContext' type.
Beans:
oauth2ClientContext (OAuth2RestOperationsConfiguration.class)
oauth2ClientContext (OAuth2RestOperationsConfiguration.class)
oauth2ClientContext (OAuth2RestOperationsConfiguration.class)
@SpringBootApplication
@RestController
@EnableOAuth2Client
@EnableAuthorizationServer
@Order(6)
public class SocialApplication extends WebSecurityConfigurerAdapter {
@Autowired
OAuth2ClientContext oauth2ClientContext;
}
Run Code Online (Sandbox Code Playgroud)
我真的无法理解它来自何处以及如何解决它.我对这个春天的东西很新,你能指出如何解决它或我应该寻找什么.我不是在创建/注释bean.
我的pom文件
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-jwt</artifactId>
<version>1.0.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>angularjs</artifactId>
<version>1.4.3</version>
</dependency> …
Run Code Online (Sandbox Code Playgroud) 是否可以在不指定组的情况下启用字段的默认验证?例如,我有豆:
class User {
@NotEmpty
private String name;
@NotEmpty(groups = UserGroup.ShouldHaveSurName.class)
private String surname;
}
Run Code Online (Sandbox Code Playgroud)
我希望在任何情况下都验证字段“name” - 如果未在控制器中为 @Validated 注释指定组,或者指定了“ShouldHaveSurName”组。我相信有这个配置,但找不到。