我POST使用以下代码发送请求,但请求以chunked(Transfer-Encoding: chunked)的形式发送.我搜索了这个问题,并说它包含Content-Length但在下面的代码中我无法弄清楚如何设置Content-Length:
@RequestMapping(value = "/contacts", method = RequestMethod.POST)
public Map<String, ContactInfo> addContactInfo(
@RequestBody Map<String, ContactInfo> ContactInfoDto) {
ContactInfo contactInfo = ContactInfoDto.get("contact");
if (contactInfo == null) {
throw new IllegalArgumentException("Contact not found.");
}
contactInfo = this.contactInfoManager.addNew(contactInfo);
Map<String, ContactInfo> map = new HashMap<>();
map.put("contact", contactInfo);
return map;
}
Run Code Online (Sandbox Code Playgroud) 我想知道如何调和以下错误?
JVM无法使用大页面内存,因为它没有足够的权限来锁定内存中的页面
设置是:
设置JAVA_OPTS = -Xms20g -Xmx20g -XX:+ UseConcMarkSweepGC -XX:+ UseParNewGC -XX:+ UseLargePages -Duser.timezone ="GMT"%DEBUG%
这发生在Windows Server 2003上.
我想获得当前正在执行的测试方法,@Before以便我可以在当前正在执行的方法上应用注释.
public class TestCaseExample {
@Before
public void setUp() {
// get current method here.
}
@Test
@MyAnnotation("id")
public void someTest {
// code
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个Spring Boot应用程序,它返回被编码为JSON响应的各种对象,我想对它们进行后处理并向某些超类添加信息.
有没有办法过滤,拦截等来自我的REST端点的对象响应,然后才能用Jackson编码为JSON.
过滤器无法工作,因为它在该HttpServlet{Request,Response}级别运行.
我收到以下异常:
org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value did not match expected type. [java.util.Date (n/a)];
nested exception is java.lang.IllegalArgumentException: Parameter value did not match expected type [java.util.Date (n/a)]
Run Code Online (Sandbox Code Playgroud)
这是我的存储库中的查询方法:
@Query("SELECT COUNT(entity) FROM Person entity WHERE trunc(entity.date) BETWEEN :startTime AND :endTime")
int getPersonBetweenDates(@Param("startTime") DateTime var1, @Param("endTime") DateTime var2);
Run Code Online (Sandbox Code Playgroud)
我在组件中的实现:
int totalPersons = personRepo.getPersonBetweenDates(new DateTime().withTimeAtStartOfDay(), DateTime.now());
Run Code Online (Sandbox Code Playgroud)
为什么我收到这个错误?实现中的两个DateTime参数似乎与我的方法中的参数相匹配?
我正在读关于DatabaseConfig在光滑的文档:
除了配置语法之外
Database,还有另一个层,其形式DatabaseConfig允许您配置Slick驱动程序和Database一起匹配.这样,只需更改配置文件,就可以轻松地在不同类型的数据库系统上进行抽象.
我没有得到这一部分,如何DatabaseConfig使底层数据库系统比Database方法更抽象?假设,我DatabaseConfig在以下测试中使用:
import org.scalatest.{Matchers, FlatSpec}
import slick.backend.DatabaseConfig
import slick.driver.JdbcProfile
import slick.driver.PostgresDriver.api._
import scala.concurrent.ExecutionContext.Implicits.global
class DatabaseConfigTest extends FlatSpec with Matchers {
def withDb(test: DatabaseConfig[JdbcProfile] => Any) = {
val dbConfig = DatabaseConfig.forConfig[JdbcProfile]("abstract")
try test(dbConfig)
finally dbConfig.db.close()
}
"DatabaseConfig" should "work" in withDb { dbConfig =>
import Supplier._
val cities = suppliers.map(_.city)
dbConfig.db.run(cities.result).map(_.foreach(println))
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,如果我将基础数据库系统从更改PostgreSQL为MySQL,除了配置更改之外,我还需要更改import将postgre API导入mysql的语句.另一方面,如果我使用 …
Slick 3有"import api"来使用特定的数据库驱动程序.例如
import slick.driver.H2Driver.api._
...DAO implementation...
Run Code Online (Sandbox Code Playgroud)
要么
import slick.driver.PostgresDriver.api._
...DAO implementation...
Run Code Online (Sandbox Code Playgroud)
如何在生产中使用postgresql,在单元测试中使用h2?
我有一个Spring Boot Web应用程序,暴露了很少的休息端点.我想知道我们如何只为选定的休息端点启用基本身份验证.假设我只/employee/{id}想要进行身份验证请求并忽略所有其他其他端点.我使用以下代码.我的问题是antMatcher唯一验证指定的请求吗?目前,它为所有其他端点启用身份验证:
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
// How does it work will it only authenticate employee &
// ignore any other request?? Its authenticating all the requests currently.
http
.authorizeRequests()
.antMatchers("/employee/*").authenticated()
.and()
.httpBasic()
.and()
.csrf()
.disable();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("admin").password("admin").roles("USER");
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 spring 为我的应用程序构建缓存服务。缓存需要从数据库填充。
我的应用程序在三个节点上运行,并希望所有三个节点都与缓存同步。如果一个节点在缓存中获得更新的值,它应该通知其他节点。
我查看了Spring Cache 抽象,它没有谈论集群环境中的缓存。
有没有办法将缓存通知传播到其他节点?
我@Inject在Spring的工作中有一些奇怪的行为.这个例子效果很好:
@Controller
@RequestMapping("/")
public class HomeController {
@Autowired
private SomeBean someBean;
@RequestMapping(method = GET)
public String showHome() {
System.out.println(someBean.method());
return "home";
}
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我取代@Autowired用@Inject,showHome方法将抛出NullPointerException,因为someBean是null.与二传手注射相同的事情.但是使用构造函数注入@Autowired并且@Inject运行良好.
为什么会这样?
我正在使用Spring 4.3.1.我的依赖关系pom.xml看起来像这样:
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependencies>
Run Code Online (Sandbox Code Playgroud) java ×8
spring ×6
scala ×2
slick ×2
spring-boot ×2
spring-mvc ×2
caching ×1
jodatime ×1
json ×1
jsr330 ×1
junit4 ×1
jvm ×1
oracle11g ×1
paging ×1
rest ×1
spring-cache ×1
spring-data ×1