我有一个弹簧启动应用程序。它包含.mvn文件夹。我应该将其添加到 `.gitignore 文件中吗?或者它是否包含需要 Git 提交和版本控制的内容?
我是 Spring 和 Spring Boot 的新手。我尝试按照我在这里找到的示例来构建一个项目:http ://www.javaguides.net/2018/09/spring-mvc-using-spring-boot2-jsp-jpa-hibernate5-mysql-example.html 。
这是我的申请:
package com.SportyShoe;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@ComponentScan(basePackages = "com.SportyShoe")
@SpringBootApplication
@EntityScan("com.SportyShoe.*")
@EnableJpaRepositories
public class SportyShoeApplication {
public static void main(String[] args) {
SpringApplication.run(SportyShoeApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的实体:
package com.SportyShoe.Entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="Shoe")
public class Shoe {
@Id
@Column(name="id")
private String id;
@Column(name="colour")
private String colour;
@Column(name="gender")
private String gender;
@Column(name="category")
private String category;
public String getId() { …Run Code Online (Sandbox Code Playgroud) 我在尝试使用 Camel Debezium SQL 服务器连接器时遇到问题。我正在尝试使用camel Debezium SQL Server 连接器捕获SQL Server 数据库表中的数据更改,并将它们接收到消息代理。我知道 JDBC SQL 服务器连接可以选择将加密设置为 false 以防止出现此问题。但我在 Camel Debezium SQL 服务器连接器中找不到类似的方法。
要使用 Camel Debezium SQL 服务器连接器,我遵循了此文档:
https://camel.apache.org/components/3.18.x/debezium-sqlserver-component.html#_samples
当我运行该应用程序时,它显示以下错误:
错误 io.debezium.embedded.EmbeddedEngine - 尝试运行连接器类“io.debezium.connector.sqlserver.SqlServerConnector”时出错
原因:com.microsoft.sqlserver.jdbc.SQLServerException:驱动程序无法使用安全套接字层 (SSL) 加密与 SQL Server 建立安全连接。错误:“PKIX 路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效证书路径”。
我的POM如下:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-parent</artifactId>
<version>3.18.1-SNAPSHOT</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-main</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-debezium-sqlserver</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>11.2.0.jre11</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-kafka</artifactId>
</dependency> …Run Code Online (Sandbox Code Playgroud) 代码
package com.example.BLModel;
import org.hibernate.annotations.Type;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MapsId;
import javax.persistence.Table;
@Entity
@Table(name = "email_template_custom")
public class EmailTemplateCustom {
@EmbeddedId
private EmailTemplateCustomId id;
@MapsId("tenantId")
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "tenant_id", nullable = false)
private Tenant tenant;
@Column(name = "email_subject", nullable = false, length = 1000)
private String emailSubject;
@Column(name = "email_content")
@Type(type = "org.hibernate.type.TextType")
private String emailContent;
public EmailTemplateCustomId getId() {
return id;
}
public void setId(EmailTemplateCustomId …Run Code Online (Sandbox Code Playgroud) 我的自定义 DTO 类如下:
public class TestDto1 {
private String key;
private String val;
@AssertTrue
private boolean isValid() {
return key !=null || val !=null;
}public class TestDto1 {
private String key;
private String val;
@AssertTrue
private boolean isValid() {
return key !=null || val !=null;
}
Run Code Online (Sandbox Code Playgroud)
我的家长 DTO 课程:
public class TestDto {
private String id;
@Valid
private TestDto1 tes;
public TestDto1 getTes() {
return tes;
}
public void setTes(TestDto1 tes) {
this.tes = tes;
}
public String getId() { …Run Code Online (Sandbox Code Playgroud) 我正在为请求日期约束创建共享组件,开始日期在结束日期之前。我想接受当前的验证请求,并使其通用,因此我输入(任何类的 Begin 和 EndDate 类成员),它将起作用。如何才能做到这一点?我在请求类上方、下面的 ProductRequest 中使用注释。
注意:如何在注释中设置开始和结束日期参数;它们可能并不总是“开始/结束”字段成员,有时它们可能是另一个类中的“开始/结束”。
@DatesRequestConstraint
public class ProductRequest {
private Long productId;
private DateTime startDate;
private DateTime EndDate;
private List<String> productStatus;
}
@Target({ TYPE, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Constraint(validatedBy = ProductValidator.class)
@Documented
public @interface DatesRequestConstraint {
String message() default "Invalid dates request.";
Class <?> [] groups() default {};
Class <? extends Payload> [] payload() default {};
}
public class ProductValidator implements ConstraintValidator<DatesRequestConstraint, ProductRequest> {
@Override
public void initialize(DatesRequestConstraint constraintAnnotation) {
ConstraintValidator.super.initialize(constraintAnnotation);
}
@Override
public boolean isValid(ProductRequest productRequest, …Run Code Online (Sandbox Code Playgroud) 最近我们将 spring-boot 版本升级到 2.7.2,将 spring Framework 版本升级到 5.3.22。从那时起,我们在其中一个应用程序中看到此错误
“需要一个‘io.micrometer.core.instrument.MeterRegistry’类型的 bean,但无法找到。”
Spring 文档说,如果有一个名为 micrometer-registry-<?> 的依赖项,那么它将自动装配所需的 MeterRegistry。我们确实对我们的项目有这种依赖性。但这并没有发生。
我们在 application.yml 中有以下属性。但执行器也不工作
management:
metrics:
export:
statsd:
enabled: true
flavor: datadog
host: localhost
port: 8125
endpoints:
web:
exposure:
include: "*"
metrics:
enabled: true
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我我在这里缺少什么吗?
我正在使用 spring boot 来调用 openfeign 客户端,并且从该 feign 的响应中我需要提取一些标头值。我该怎么做。有人可以帮忙吗?请帮我看看我们是否可以这样做!
我希望在微服务启动之前有一些特定数量的连接可供使用。我正在使用 Hikari Pool 和 Spring Boot。
我使用特定数字的循环并调用“SELECT 1 FROM DUAL”来手动创建连接,但它似乎不是创建多个连接,而是一次又一次地重复使用相同的连接。
这个怎么做 ?
我正在用来spring-security-web:5.6.3构建 RESTful API。该 API 通过不记名令牌 (JWT) 和基于角色的授权进行工作身份验证。
问题是,当经过身份验证的用户未被授权访问某个资源时,API 会返回 500 错误而不是 403。日志输出:
org.springframework.security.access.AccessDeniedException: Access is denied
at org.springframework.security.access.vote.AffirmativeBased.decide(AffirmativeBased.java:73)
at org.springframework.security.access.intercept.AbstractSecurityInterceptor.attemptAuthorization(AbstractSecurityInterceptor.java:239)
at org.springframework.security.access.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:208)
at org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:58)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708)
at com.<redacted>.<redacted>.api.controller.RedactedController$$EnhancerBySpringCGLIB$$8274b324.getWorkInstructions(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:655)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at …Run Code Online (Sandbox Code Playgroud) spring-boot ×10
java ×6
hibernate ×2
spring ×2
spring-mvc ×2
annotations ×1
apache-camel ×1
apache-kafka ×1
feign ×1
github ×1
gitignore ×1
header ×1
hikaricp ×1
maven ×1
micrometer ×1
oracle ×1
response ×1
rest ×1
spring-jdbc ×1
sql-server ×1
validation ×1