我尝试将我的应用程序从spring boot 1.5迁移到2.0问题是我找不到EmbeddedServletContainerCustomizer.任何想法如何通过?
@Bean
public EmbeddedServletContainerCustomizer customizer() {
return container -> container.addErrorPages(new ErrorPage(HttpStatus.UNAUTHORIZED, "/unauthenticated"));
}
Run Code Online (Sandbox Code Playgroud)
更新: 我在org.springframework.boot.autoconfigure.web.servlet包中找到它作为ServletWebServerFactoryCustomizer.
@Bean
public ServletWebServerFactoryCustomizer customizer() {
return container -> container.addErrorPages(new ErrorPage(HttpStatus.UNAUTHORIZED, "/unauthenticated"));
}
Run Code Online (Sandbox Code Playgroud)
但是有一个错误:无法解决方法
'addErrorPages(org.springframework.boot.web.server.ErrorPage)'
我还必须将新错误页面的导入更改org.springframework.boot.web.servlet为org.springframework.boot.web.server
我当前的解决方案: 我的应用程序由部署到 ECS 的两个单独的服务/容器组成。这些服务位于虚拟私有云 (VPC) 内部,为了公开我创建的 EC2 应用程序负载均衡器(该应用程序运行完美),我可以通过负载均衡器 URL 轻松访问该应用程序。
我想要实现的目标: 目前我正在尝试创建一个链接到上述负载均衡器的API网关,以通过API网关而不是负载均衡器访问应用程序。
为了实现这一目标,我 找到了一个 AWS 教程,它基本上完成了我想要做的事情,所以我一步步学习了本教程
ANY /{proxy+}来捕获基本上所有的东西一切都是一步一步的,与教程中的相同,但不幸的是最后一步我应该看到我看到的网页ERROR: 503 {"message":"Service Unavailable"}
我还做了什么来解决这个问题:
{
"requestId": "PgELwjAyjoEEPgQ=",
"ip": "185.244.96.51",
"requestTime": "24/Mar/2022:18:09:40 +0000",
"httpMethod": "GET",
"routeKey": "ANY /{proxy+}",
"status": "503",
"protocol": "HTTP/1.1",
"responseLength": "33"
}
Run Code Online (Sandbox Code Playgroud)
问题是,我在这里缺少什么?
我猜问题出在VPC链路和负载均衡器之间的连接上,但说实话我不知道如何检查和验证它。我一步一步点击了所有内容,在很多地方都有单选选项,所以我真的很困惑我可能在哪里犯了错误。这是基础设施的说明性照片以及我的猜测问题可能出在哪里(但这仍然是猜测。
我的问题可能很简单,但是 hibernate-envers 的文档说我只需要 2 个步骤就可以使 hibernate envers 工作:
类路径上的 hibernate-envers jar,
实体上的@Audited 注释。
首先我补充说:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-envers</artifactId>
<version>5.2.12.Final</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
其次,我在实体上方添加了 @Audited 注释:
@Entity
@Audited
@Table(name = "users")
public class User {...}
Run Code Online (Sandbox Code Playgroud)
在这两个步骤之后,我可以选择:
使用 hbm2ddl 工具生成自动模式
单独创建模式。
教程/文档等中的很多人都说你应该单独做,所以这就是我的模式的样子(在百里香叶中)。
要手动创建模式,我必须使用一个特殊表(通常称为 revinfo)创建变更集:
<createTable tableName="revinfo">
<column name="rev" type="integer">
<constraints primaryKey="true"/>
</column>
<column name="revtstmp" type="bigint"></column>
</createTable>
Run Code Online (Sandbox Code Playgroud)
现在我只需要添加名为 tablename_AUD 的新表(ofc 我可以通过在我的实体 @AuditTable("new_name") 中添加新注释来更改此名称,但事实并非如此)并添加了 rev 和 revtype 列。
这是我在 liquibase 中的现有表之一:
<createTable tableName="users">
<column name="id" type="int">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="email" type="varchar(200)">
<constraints unique="true" nullable="false"/>
</column> …Run Code Online (Sandbox Code Playgroud) 我正在阅读很多关于javadoc的文章,但是当"样板"开始时仍然无法管理.在这个例子中:
/**
* Returns a list of tasks for specific user
* @param userId
* @return Selected list of tasks
*/
List<Task> getTasksForUser(Integer userId);
/**
* Returns a list of tasks in chosen month and year
* @param month
* @param year
* @return selected list of tasks
*/
List<Task> getTasks(Integer month, Integer year);
Run Code Online (Sandbox Code Playgroud)
我可以以某种方式执行它们以减少样板或我应该删除它们吗?
为什么75%的文章称为"Javadoc的最佳实践,我们有重复?"例如:
/**
* Returns a list of tasks using params month, year
* @param month
* @param year
* @return a list of tasks
*/ …Run Code Online (Sandbox Code Playgroud) 根据官方网站的信息,我添加了最新的依赖并开始发展.
首先,我创建了我感兴趣的数据模型:
public class Data{
String parametr1;
//geters and setters ommited
}
Run Code Online (Sandbox Code Playgroud)
第二步是添加服务:
public interface GitHubService {
@GET("/repos/{owner}/{repo}")
Call<Data> repoInfos(@Path("user") String owner, @Path("repo") String repo);
Retrofit retrofit = new Retrofit.Builder().baseUrl("https://api.github.com/").build();
}
Run Code Online (Sandbox Code Playgroud)
第三个是添加实施:
@Service
public class GitHubServiceImpl implements GitHubService {
final GitHubService gitHubService = GitHubService.retrofit.create(GitHubService.class);
@Override
public Call<DetailDto> repoDetails(String owner, String repo) {
return gitHubService.repoDetails(owner, repo);
}
}
Run Code Online (Sandbox Code Playgroud)
但是有一个错误:
java.lang.IllegalArgumentException: Could not locate ResponseBody converter for class model.Data.
Run Code Online (Sandbox Code Playgroud)
我用参数创建了端点:
@GetMapping("/me")
public MeDto getInfo(@RequestParam("param") Set<Integer> params) {
...
}
Run Code Online (Sandbox Code Playgroud)
一切正常,但我需要单独发送 ID,例如
/me?param=1¶m=2
Run Code Online (Sandbox Code Playgroud)
有没有办法使它成为:
/me?param=1,2...N
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢。
我用教程创建了一个基本的网络套接字。
这是一个配置:
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic");
config.setApplicationDestinationPrefixes("/app");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/chat");
registry.addEndpoint("/chat").withSockJS();
}
}
Run Code Online (Sandbox Code Playgroud)
这是消息处理控制器:
@MessageMapping("/chat")
@SendTo("/topic/messages")
public OutputMessage send(Message message) throws Exception {
return new OutputMessage("Hello World!");
}
Run Code Online (Sandbox Code Playgroud)
一切正常,但根据我的调查,默认情况下 WebSockets 看起来有一个应用程序范围(通过连接到通道,我可以看到来自所有用户的所有调用)。
我想要做的是只能看到来自当前用户会话或当前视图的调用。关于如何应用这些配置的任何想法?
java websocket spring-boot spring-messaging spring-websocket
我有一个名为Time with fields的实体/表单:
Integer id;
Date date;
Integer value;
Run Code Online (Sandbox Code Playgroud)
另一种称为SummaryForm的形式
String title;
String descr;
List<Object> newList;
Run Code Online (Sandbox Code Playgroud)
如何使用Java 8接口提高地图使用率.现在我有一个if语句:
if (map.containsKey(key)) {
map.get(key).newList().add(new SummaryForm(time.getDate(), time.getValue()));
}
Run Code Online (Sandbox Code Playgroud)
是否有任何简单的方法来改进它以避免if语句,使用map.containsKey?在我看来,我需要像putIfPresent这样的东西,但似乎只有putIfAbsent方法.
这个例子很好用。
@Query("select t from TimeTable t where MONTH(t.date) = ?1 and YEAR(t.date) = ?2")
List<TimeTable> findAll(Integer month, Integer year);
Run Code Online (Sandbox Code Playgroud)
现在我尝试用下面的名称替换?1和?2
@Query("select t from TimeTable t where MONTH(t.date) =month and YEAR(t.date) =:year")
List<TimeTable> findAll(Integer month, Integer year);
Run Code Online (Sandbox Code Playgroud)
这不起作用并产生错误:
org.springframework.dao.InvalidDataAccessApiUsageException:该位置为[1]的参数不存在;嵌套异常是java.lang.IllegalArgumentException:具有该位置[1]的参数不存在
还有这个
@Query("select t from TimeTable t where MONTH(t.date) =:month and YEAR(t.date) =:year")
List<TimeTable> findAll(Integer month, Integer year);
Run Code Online (Sandbox Code Playgroud)
产生错误:
org.springframework.dao.InvalidDataAccessApiUsageException:参数绑定的名称不能为null或为空!在JDK <8上,您需要对命名参数使用@Param,在JDK 8或更高版本上,请确保使用-parameters进行编译。嵌套异常为java.lang.IllegalArgumentException:参数绑定的名称不能为null或为空!在JDK <8上,您需要对命名参数使用@Param,在JDK 8或更高版本上,请确保使用-parameters进行编译。
更新:
就像上面的错误所示,我不需要在JDK 8上使用@Param,但是使用@Param的解决方案有效:
List<TimeTable> findAll(@Param("month") Integer month, @Param("year") Integer year);
Run Code Online (Sandbox Code Playgroud)
当我删除@Params时,它将再次出现此错误。
当我创建Spring Boot Application时,它会生成2个类:
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
第二个是测试:
@RunWith(SpringRunner.class)
@SpringBootTest
public class AppTest {
@Test
public void contextLoads() {
}
}
Run Code Online (Sandbox Code Playgroud)
更新:
我喜欢readed回答这个,但它并没有给我一个明确的答复。
java ×9
spring ×4
spring-boot ×3
amazon-ec2 ×1
amazon-vpc ×1
dictionary ×1
github ×1
github-api ×1
hibernate ×1
java-8 ×1
javadoc ×1
jpa ×1
jpql ×1
parameters ×1
retrofit ×1
retrofit2 ×1
testing ×1
websocket ×1