【java – Spring Tool Suite 3.5.0上的Spring Roo项目】教程文章相关的互联网学习教程文章

java – Spring Boot – 如何在开发过程中禁用@Cachable?【代码】

我正在寻找两件事: >如何使用Spring启动“dev”配置文件禁用开发期间的所有缓存.在application.properties中,没有seam作为一般设置来关闭它.什么是最简单的方法?>如何禁用特定方法的缓存?我试着像这样使用SpEl: @Cacheable(value =“complex-calc”,condition =“#{${spring.profiles.active}!=’dev’}”)public String someBigCalculation(String input){ …} 但我可以让它发挥作用.关于SO的问题有几个问题,但它们指的是X...

java – Spring MVC(async)vs Spring WebFlux

我正在尝试了解Spring WebFlux.到目前为止我发现的东西都是反应核心,没有Servlet API,没有每个请求的线程,HTTP 2,服务器推送,应用程序/流json. 但是Spring MVC中的异步调用有什么区别?我的意思是在Spring MVC中,当你返回Future,DefferedResult等时,你会在一个单独的线程中执行请求处理程序(控制器方法)中的逻辑,因此你也可以从保存线程池资源以便调度请求中受益. 那么请你强调与此相关的差异吗?为什么WebFlux在这里更好? 非常感...

java – Spring Data JPA与findBy / findAllBy的区别【代码】

在以下之间使用Spring Data JPA关键字时是否有任何区别:List<SomeEntity> findBySomeCondition();和List<SomeEntity> findAllBySomeCondition();解决方法:不,它们之间没有区别,它们将执行完全相同的查询,当从方法名称派生查询时,Spring Data会忽略All部分.唯一重要的一点是By关键字,其后面的任何内容都被视为一个字段名称(除了OrderBy之外的其他关键字,它们可能会导致一些奇怪的方法名称,如findAllByOrderByIdAsc). 这意味着这样的...

java – Spring jUnit测试属性文件【代码】

我有一个jUnit测试,它有自己的属性文件(application-test.properties)和它的spring配置文件(application-core-test.xml). 其中一种方法使用spring config实例化的对象,它是一个spring组件.类中的一个成员从application.properties派生它的值,application.properties是我们的主要属性文件.通过jUnit访问此值时,它始终为null.我甚至尝试更改属性文件以指向实际的属性文件,但这似乎不起作用. 这是我访问属性文件对象的方式@Component ...

java – Spring:从命令行覆盖一个application.property【代码】

我有一个带有默认变量值的application.properties文件.我希望能够在使用mvn spring-boot:run运行时更改其中一个.我找到了如何更改整个文件,但我只想更改其中一个或两个属性.解决方法:您可以将各个属性作为命令行参数传递.例如,如果要设置server.port,则可以在启动可执行jar时执行以下操作:java -jar your-app.jar --server.port=8081或者,如果你正在使用mvn spring-boot:run:mvn spring-boot:run -Drun.arguments="--server.po...

java – 为什么Spring Boot Application类需要@Configuration注释?【代码】

我正在学习Spring框架,但我无法理解@Configuration注释到底意味着什么以及应该注释哪些类.在Spring Boot文档中,据说Application类应该是@Configuration类.Spring Boot favors Java-based configuration. Although it is possibleto call SpringApplication.run() with an XML source, we generallyrecommend that your primary source is a @Configuration class.试图了解@Configuration我发现使用@Configuration注释一个类表明该类...

java – Spring:已经为此响应调用了getOutputStream()【代码】

我知道还有很多其他帖子处理同样的错误,但所有这些都是关于JSP / GSP页面或者在我的情况下对其他任何不太有用的原因.我正在使用Spring MVC和Thymeleaf.以下功能用于下载文件.@RequestMapping(value = "/test/download/*", method = RequestMethod.GET) public String getFile(HttpServletResponse response) {ServletOutputStream stream = null;try{stream = response.getOutputStream();MultipartFile f = test.getFile();InputS...

java – Spring Rest Controller返回特定字段【代码】

我一直在思考使用Spring MVC设计JSON API的最佳方法.我们都知道IO很昂贵,因此我不想让客户端进行多次API调用以获得他们需要的东西.但与此同时,我不一定要回厨房水槽. 作为一个例子,我正在开发类似于IMDB的游戏API,而不是用于视频游戏. 如果我返回与游戏相关的所有内容,它将看起来像这样. / API /游戏/ 1{"id": 1,"title": "Call of Duty Advanced Warfare","release_date": "2014-11-24","publishers": [{"id": 1,"name": "Activis...

java – Spring启动测试失败说,由于缺少ServletWebServerFactory bean,无法启动ServletWebServerApplicationContext【代码】

测试类: – @RunWith(SpringRunner.class) @SpringBootTest(classes = { WebsocketSourceConfiguration.class,WebSocketSourceIntegrationTests.class }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {"websocket.path=/some_websocket_path", "websocket.allowedOrigins=*","spring.cloud.stream.default-binder=kafka" }) public class WebSocketSourceIntegrationTests {private String port =...

java – Spring,不支持请求方法’POST’【代码】

首先要道歉请问这个反复的问题.. 实际上在我的春季应用程序中我有user.jsp和professional.jsp 这是我的User.jsp:<form:form action="profile/user" modelAttribute="profile"><div><jsp:include page="professional.jsp"></jsp:include></div></form:form>这是我的professional.jsp:<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%...

Java Spring resttemplate字符编码【代码】

我正在使用Java Spring Resttemplate通过get请求获取json.我得到的JSON不是特殊字符,而是some或一些奇怪的东西.所以我猜这个字符编码有些不对劲.我在互联网上找不到任何帮助.我现在使用的代码是:String json = restTemplate.getForObject(overPassStatementPostCode,String.class,params);解决方法:您只需要将StringHttpMessageConverter添加到模板的消息转换器:RestTemplate template = new RestTemplate(); template.getMessag...

java – Spring – 在jsp文件上显示图像【代码】

我的模型商店图像用文件名(作为字符串)和数据(作为字节数组)描述.我使用Hibernate,这是我的模型:@Entity public class Image {private Long id;private String name;private byte[] data;@Id@GeneratedValue@Column(name = "IMAGE_ID")public Long getId() {return id;}public void setId(Long id) {this.id = id;}@Column(nullable = false, length = 100)public String getName() {return name;}public void setName(String nam...

java – 为什么Spring的jdbcTemplate.batchUpdate()这么慢?【代码】

我正在尝试找到更快的批量插入方法. 我试着用jdbcTemplate.update(String sql)插入几个批次,其中sql由StringBuilder构建,看起来像:INSERT INTO TABLE(x, y, i) VALUES(1,2,3), (1,2,3), ... , (1,2,3)批量大小正好是1000.我插入了近100批.我使用StopWatch检查了时间并找出了插入时间:min[38ms], avg[50ms], max[190ms] per batch我很高兴,但我想让我的代码变得更好. 之后,我尝试使用jdbcTemplate.batchUpdate,如:jdbcTemplate.b...

java – spring数据动态组合@query查询【代码】

我有一种情况,我必须在某些方法中编写JPQL查询,然后将此查询传递给spring数据查询方法,以用作@Query注释中的查询@Query(value = ":DyanamicQuery") List<PrizeInsuranceConfiguration> filterConfigurPrizeInsurance(String DyanamicQuery);或者至少是条件部分@Query(value = "SELECT c FROM PrizeInsuranceConfiguration c WHERE :DyanamicConditions") List<PrizeInsuranceConfiguration> filterConfigurPrizeInsurance(String ...

java – Spring的SecurityContextHolder.getContext().getAuthentication()在HTTPS / SSL中使用RedirectView后返回【代码】

我有一个典型的Spring MVC在Tomcat上运行.切换系统以在HTTPS上运行(一切正常在HTTP下运行正常)后,登录停止工作.原因是Spring的SecurityContextHolder.getContext().getAuthentication()对象在使用RedirectView后变为null. 我已经搜索了答案,我发现了唯一一个在viewResolver bean设置中将属性redirectHttp10Compatible设置为false的建议.这没有用. 我还检查了整个重定向,我的会话ID保持不变,连接仍然是安全的,即http和https之间的变...