对于Mentor to Students的实体,我的关系低于1米.导师有复合主键,我在学生中用作外键
@Entity
public class Mentor implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private MentorPK id;
private String email;
@OneToMany(mappedBy="mentor")
private Set<Student> students;
public MentorPK getId() {
return id;
}
//getters and setters
}
@Embeddable
public class MentorPK implements Serializable {
private static final long serialVersionUID = 1L;
private String name;
private String add;
//getters and setters
//override equals and hashcode
}
@Entity
public class Student implements Serializable{
private static final long serialVersionUID = 1L; …Run Code Online (Sandbox Code Playgroud) 在我的 Spring Boot 项目中,我必须使用一个外部库,它在 Spring 上下文中定义了 beans。因此,在我的应用程序类中,我在下面添加了我的项目和外部库的基础包,
@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
@EnableHypermediaSupport(type = { EnableHypermediaSupport.HypermediaType.HAL })
@EnableSwagger2
@ComponentScan(basePackages = {"com.mylibrary.test", "com.otherlibrary.springtool"})
//@EnableDiscoveryClient
public class Application extends RepositoryRestMvcConfiguration {
}
Run Code Online (Sandbox Code Playgroud)
但是其他库(例如@Configuration)中的bean没有初始化?
我有一个带有主服务器、从服务器和 3 个哨兵服务器的 Redis 集群。主服务器和从服务器映射到 dns 名称为 node1-redis-dev.com、node2-redis-dev.com。redis服务器版本是2.8
我将以下内容包含在我的 application.properties 文件中。
spring.redis.cluster.nodes=node1-redis-dev.com:6379,node2-redis-dev.com:6379
spring.redis.pool.max-idle=8
spring.redis.pool.min-idle=0
spring.redis.pool.max-active=-1
spring.redis.pool.max-wait=-1
Run Code Online (Sandbox Code Playgroud)
但是当我检查 StringRedisTemplate 时,我在 JedisConnectionFactory 的 hostName 属性下看到 localhost 而不是集群信息。
我还看到 JedisPool 的 CreationStackTrace 属性中出现异常。
java.lang.Exception
at org.apache.commons.pool2.impl.BaseGenericObjectPool.<init>(BaseGenericObjectPool.java:139)
at org.apache.commons.pool2.impl.GenericObjectPool.<init>(GenericObjectPool.java:107)
at redis.clients.util.Pool.initPool(Pool.java:43)
at redis.clients.util.Pool.<init>(Pool.java:31)
at redis.clients.jedis.JedisPool.<init>(JedisPool.java:80)
at redis.clients.jedis.JedisPool.<init>(JedisPool.java:74)
at redis.clients.jedis.JedisPool.<init>(JedisPool.java:55)
at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.createRedisPool(JedisConnectionFactory.java:228)
at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.createPool(JedisConnectionFactory.java:204)
Run Code Online (Sandbox Code Playgroud)
CasheRepository 类如下所示,
@Component
@CacheConfig(cacheNames = "enroll", cacheManager = "enrollCM")
public class EnrollCashRepository {
@Autowired
private StringRedisTemplate stringRedisTemplate;
//Other methods
}
Run Code Online (Sandbox Code Playgroud)
我正在使用 spring boot 1.3.4 和 spring-boot-starter-redis 1.2.7,它导入 …
我认为NOT IN行为与!=查询中的行为相同.但是使用的查询!=返回的行多于使用的查询NOT IN:
SELECT count(A.NO)
FROM A
WHERE
A.CODE != 'a'
AND
A.CODE != 'b'
AND
A.CODE != 'c'
AND
A.NAME != 'd'
AND
A.NAME != 'e'
Run Code Online (Sandbox Code Playgroud)
返回1566行,而
SELECT count(A.NO)
FROM A
WHERE
A.CODE NOT IN ('a','b','c')
AND
A.NAME NOT IN ('d','e')
Run Code Online (Sandbox Code Playgroud)
只返回1200行.
我想NOT IN排除NULL价值 - 这是唯一的区别吗?
我正在使用junit4放心.在我的测试方法中,我在mongodb中创建一个对象,当我运行测试时,它也成功地持久存在.但我需要存储创建的ID,所以我尝试获取响应正文.但这response.getBody().asString()是空的.
@Test
public void testA() throws JSONException {
Map<String,Object> createVideoAssignmentParm = new HashMap<String,Object>();
createVideoAssignmentParm.put("test1", "123");
Response response = expect().statusCode(201).when().given().contentType("application/json;charset=UTF-8")
.headers(createVideoAssignmentParm).body(assignment).post("videoAssignments");
JSONObject jsonObject = new JSONObject(response.getBody().asString());
id= (String)jsonObject.getString("assignmentId");
}
Run Code Online (Sandbox Code Playgroud)
当我从外部调用其余端点时,它会返回响应主体以及相关字段,因此其余API没有问题.
如果没有上述问题的答案那么你们将如何使用放心测试带有返回体的帖子,以便我可以尝试这种方式.
我的控制器方法看起来像,
@RequestMapping(value = "/videoAssignment", produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE, method = RequestMethod.POST)
@ResponseBody
public HttpEntity<VideoAssignment> createVideoAssingnment(
//@ApiParam are there..){
//other methods
return new ResponseEntity<>(va, HttpStatus.CREATED);
}
Run Code Online (Sandbox Code Playgroud) 领域层和持久层是指相同还是不同。域层是我们通常映射到数据库表的DAO,对吗?那么持久层意味着相同还是更多?
如果我们将映射到数据库表的 POJO 称为 DAO,我们所说的驻留查询执行并填充这些 DAO (POJOS) 的类。
最佳做法是什么?将查询执行代码保留在那些 POJO 中还是将它们作为一个单独的类?我的意思是示例假设 A 是到数据库表 A 的类映射。我们是否需要实现像 ADaoImpl 这样的单独类来放置类 A 所需的查询相关代码?我相信这是不对的?将与所有 DAO 类相关的所有 DAO 对象填充、查询执行等保存在一个名为 RBMSDaoImpl 的单个类中,这难道不是最佳实践吗?所以我们称该类为属于 DAO 层的 out 应用程序的 DAO 实现类,对吗?
总而言之,POJOS(DAO) 和 DAOImpl 是我们应用程序的 DAO 层,对吗?持久层是..?
谢谢。
弹簧org.springframework.web.servlet.HandlerInterceptor和 org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
我计划为我的应用程序添加身份验证。但是在HandlerInterceptor Doc中,
在异步处理方案中,处理程序可以在主线程退出时在单独的线程中执行,而无需呈现或调用postHandle和afterCompletion回调。
因此,在这种情况下,如果处理程序在单独的线程中执行,我会发现HandlerInterceptor不适合身份验证。
实施身份验证的最佳方法是什么?
我在弹簧启动应用程序中配置了过滤器的代码.当我发出请求时,我的第二个过滤器是B,不会调用.
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;
@Configuration
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity webSecurity) throws Exception {
webSecurity.ignoring().antMatchers(HttpMethod.GET, "/health");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http.addFilterBefore(new A(), BasicAuthenticationFilter.class);
http.addFilterAfter(new B(), new A().getClass());
}
}
import org.springframework.web.filter.GenericFilterBean;
public class A extends GenericFilterBean {
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)
throws IOException, ServletException {
System.out.println("filter A");
}
}
import org.springframework.web.filter.GenericFilterBean;
public class B extends GenericFilterBean {
@Override …Run Code Online (Sandbox Code Playgroud) 我使用Mongo db 2.4.10的spring boot 1.2.8.我打算将mongo db升级到3.2.0.
所以使用当前的sprinb boot 1.2.8我在下面使用pom,
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我在依赖层次结构中看到它带有mongo-java-driver版本2.12.5
但是我在mongo java驱动程序doc中读到它,即使版本为2.14,它也不支持所有MongoDB 3.2功能(例如,读取关注)
所以我将spring boot升级到1.3.3的最新版本,期待我得到一个支持所有mongo db 3.2功能的mongo-java-driver版本3.2.
但我得到了Springboot 1.3.3的mongo-java-driver 2.13.3
那么如何升级我的应用程序以支持mongo db版本3.2?
编辑:
随着最新的春季启动1.3.4以下是层次结构,
spring-boot-starter-data-mongodb 1.3.4 [compile]
-mongo-java-driver 2.13.3 [compile]
-spring-data-mongodb 1.8.4 [compile]
-mongo-java-driver 2.13.3 [omitted for conflict with 2.13.3]
Run Code Online (Sandbox Code Playgroud)
该参考文档说,什么春数据的MongoDB 1.9的新功能=>断言与MongoDB的3.0和MongoDB Java驱动程序的兼容性3.2
Spring Data MongoDB 1.7中的新功能=>断言与MongoDB 3.0和MongoDB Java驱动程序3-beta3的兼容性
所以说的是,如果我使用上面提到的弹簧启动1.3.4的弹簧启动1.3.4,它将支持mongo db 3.2的所有功能,虽然我得到spring-data-mongodb 1.8.4?
我正在为 Jenkins 设置 AWS_ env 变量,如下所示
sudo apt-get update -y
sudo apt-get install -y python3 python-pip python-devel
sudo pip install awscli
S3_LOGIN=$(aws sts assume-role --role-arn rolename --role-session-name s3_session)
export AWS_CREDENTIAL_PROFILES_FILE=~/.aws/credentials
export AWS_ACCESS_KEY_ID=$(echo ${S3_LOGIN}| jq --raw-output '.Credentials|"\(.AccessKeyId)"')
export AWS_SECRET_ACCESS_KEY=$(echo ${S3_LOGIN} | jq --raw-output '.Credentials|"\(.SecretAccessKey)"')
export AWS_SESSION_TOKEN=$(echo ${S3_LOGIN} | jq --raw-output '.Credentials|"\(.SessionToken)"')
aws configure set default.region us-east-2
aws configure set AWS_ACCESS_KEY_ID $AWS_ACCESS_KEY_ID
aws configure set AWS_SECRET_ACCESS_KEY $AWS_SECRET_ACCESS_KEY
Run Code Online (Sandbox Code Playgroud)
但是当我尝试从代码中获取它们时,sdk 无法读取已设置的环境变量
AWSCredentials evc = new EnvironmentVariableCredentialsProvider().getCredentials();
AmazonS3Client amazonS3 = new AmazonS3Client(evc);
amazonS3.setRegion(RegionUtils.getRegion("us-east-2"));
Run Code Online (Sandbox Code Playgroud)
com.amazonaws.AmazonClientException:无法从环境变量(AWS_ACCESS_KEY_ID(或 AWS_ACCESS_KEY)和 …