我正在使用TestRestTemplate
我们产品的集成测试.
我有一个看起来像这样的测试:
@Test
public void testDeviceQuery() {
ResponseEntity<Page> deviceInfoPage = template.getForEntity(base, Page.class);
// validation code here
}
Run Code Online (Sandbox Code Playgroud)
此特定请求需要Header值.有人可以告诉我如何在TestRestTemplate
电话中添加标题吗?
有没有办法我们可以有条件地声明一个Spring bean:
<bean class="path.to.the.class.MyClass" if="${1+2=3}" />
Run Code Online (Sandbox Code Playgroud)
它将是有用的,而不必使用配置文件.我没有考虑具体的用例,但它来到我身边.
我想保护一个URL,同时允许匿名访问其他所有内容.
我在互联网上看到的Java配置示例似乎都表明您需要明确地显示permitAll
每个URL,并且适用hasRole
于需要保护的URL.在我的情况下,这会创建一个非常笨拙的java代码,我每次向应用程序添加新URL时都会对其进行修改.我可以使用更简单的java配置吗?
并且还要注意,在我的情况下,我正在保护的URL是一个子资源,比如说employee/me
,我希望employee/list
等等,可以匿名访问.
目前我正在使用Spring Cache和@Cacheable
/ @CacheEvict
annotations.
我想得到某种类似的控制台日志声明 "INFO: i got those values from the cache, NOT from the host. awesome"
有一个干净,简单的方法吗?slf4j
如果有任何兴趣,我们显然使用btw.
我正在使用春季启动项目.我想了解不同背景的目的和关系?
例如,Spring Security上下文,Spring Context,Servlet Context等(还有更多的上下文吗?)
什么是默认的请求方法类型@RequestMapping
?
@RequestMapping(value = "addGoal")
public String addGoal(Model model) {...}
Run Code Online (Sandbox Code Playgroud) 在IntelliJ Idea 14中,我可以使用以下内容:
文件>新建项目> Spring>从模板创建项目> Spring MVC
使用Maven创建Spring MVC应用程序模板.现在这个功能在其他地方吗?
问题是,如果我不使用模板,则没有webapp
制作文件夹.我在创建项目时检查Spring + Spring MVC + Web应用程序,但没有webapp
文件夹.
有任何想法吗?
我正在尝试解决某些RequestMapping
方法的某些参数,从请求体中提取值并验证它们并将它们注入到某些带注释的参数中.
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
// 1, get corresponding input parameter from NativeWebRequest
// 2, validate
// 3, type convertion and assemble value to return
return null;
}
Run Code Online (Sandbox Code Playgroud)
最大的问题是我发现HttpServletRequest
(get from NativeWebRequest
)无法读取输入流(某些参数在请求体中)不止一次.那么我怎样才能多次检索Inputstream
/ Reader
或请求体?
我是Spring boot和Spring Security的新手.我目前的Spring启动版本1.3.7.RELEASE有什么问题吗?我该如何解决这个问题?
我SecurityConfig.java
看起来如下:
@Configuration
@EnableGlobalMethodSecurity(securedEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureAuth(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("thomas")
.password("password")
.and()
.withUser("joe")
.password("password")
.roles("USER");
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>springsecuritydemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>springsecuritydemo</name>
<description>springsecuritydemo</description>
<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>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<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.boot</groupId> …
Run Code Online (Sandbox Code Playgroud)