对于Java枚举类型,我了解到MongoDB有两种解决方案:序列化和使用Jackson的ObjectMapper.MongoRepository可以使用这些方法中的任何一种使用枚举数据类型,或者我必须编写自定义存储库吗?
我刚刚开始使用 kustomize。我有以下用于 kustomize 的 yaml 文件:
ls -l ./kustomize/base/
816 Apr 18 21:25 deployment.yaml
110 Apr 18 21:31 kustomization.yaml
310 Apr 18 21:25 service.yaml
Run Code Online (Sandbox Code Playgroud)
其中,deployment.yaml 和 service.yaml 是使用 jib 生成的文件,并且运行良好。kustomization.yaml 的内容如下:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- service.yaml
- deployment.yaml
Run Code Online (Sandbox Code Playgroud)
并且在另一个目录中
ls -l ./kustomize/qa
133 Apr 18 21:33 kustomization.yaml
95 Apr 18 21:37 update-replicas.yaml
Run Code Online (Sandbox Code Playgroud)
在哪里
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../base
patchesStrategicMerge:
- update-replicas.yaml
Run Code Online (Sandbox Code Playgroud)
和
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 2
Run Code Online (Sandbox Code Playgroud)
运行“kustomize build ./kustomize/base”后,我运行
~/kustomize …
Run Code Online (Sandbox Code Playgroud) 我正在努力将Spring 3项目转换为Spring 4 + Spring Boot.我不知道这是否是正确的做法.我将Spring Security XML配置转换为基于Java的配置,如下所示:
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/", "/home").permitAll()
.anyRequest().authenticated();
http.formLogin()
.defaultSuccessUrl("/afterLogin")
.loginPage("/profiles/lognin/form")
.failureUrl("/accessDenied")
.and()
.authorizeRequests()
.regexMatchers("....")
.hasRole("ROLE_USER")
.antMatchers("....")
.hasRole("ROLE_USER")
//....
;
}
@Override
protected void configure(AuthenticationManagerBuilder authManagerBuilder)
throws Exception {
authManagerBuilder.authenticationProvider(this.getDaoAuthenticationProvider());
}
// ....
}
Run Code Online (Sandbox Code Playgroud)
当我点击主页URL时,我得到了Spring Security默认登录弹出面板.在我看来,上面的配置没有生效,但Spring Boot中的默认Spring Security配置却没有.如果是这样,如何覆盖默认值?
我遇到了以前见过的Git合并冲突。
>git pull origin dev
From https://scm.starbucks.com/roastery-milan/choreographer
* branch dev -> FETCH_HEAD
CONFLICT (modify/delete): <file name omitted> deleted in HEAD and modified in 01b734b9ae8594f03f5e481b123d80e41fb54d7c. Version 01b734b9ae8594f03f5e481b123d80e41fb54d7c of <file name omitted> left in tree.
...
Automatic merge failed; fix conflicts and then commit the result.
Run Code Online (Sandbox Code Playgroud)
当我查看那些冲突的文件时,看不到任何冲突迹象。我想我需要更换Git HEAD。但是,怎么做呢?
顺便说一句,我们的GitHub最近进行了一些更改,并且有更多分支可供分期。
更新:谢谢大家的投入。现在,我知道如何解决这个问题。
在我们的 github 进行了两因素身份验证设置后,由于“找不到存储库”的错误,我无法在命令行上执行拉取或推送操作。
C:\myproject>git push origin mybranch
Username for 'https://github.com': myname
Password for 'https://myname@github.com':
remote: Repository not found.
fatal: repository 'https://github.com/myproject.git/' not found
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题?
在 Spring Boot 应用程序中,我有一个内存中的 Spring Security 设置。它可以按需要工作。
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("kevin").password("password1").roles("USER").and()
.withUser("diana").password("password2").roles("USER", "ADMIN");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.httpBasic().and()
.authorizeRequests()
.antMatchers(HttpMethod.POST, "/foos").hasRole("ADMIN")
.antMatchers(HttpMethod.PUT, "/foos/**").hasRole("ADMIN")
.antMatchers(HttpMethod.PATCH, "/foos/**").hasRole("ADMIN")
.antMatchers(HttpMethod.DELETE, "/foos/**").hasRole("ADMIN")
.and()
.csrf().disable();
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我使用以下代码将其转换为基于数据库的方法。
@Entity
class Account {
enum Role {ROLE_USER, ROLE_ADMIN}
@Id
@GeneratedValue
private Long id;
private String userName;
// @JsonIgnore
private String password;
@ElementCollection(fetch = FetchType.EAGER)
Set<Role> roles = …
Run Code Online (Sandbox Code Playgroud) 根据文章Better application events in Spring Framework 4.2,我设置了所有相关类。我的大部分代码都可以正常工作,但在侦听器的方法中出现异常。
控制器:
@PostMapping("/Foos")
public ResponseEntity<Foo> handle(@RequestBody Foo foo){
Optional<Foo> f = fooService.save(foo);
return f.isPresent() ? new ResponseEntity<>(f, HttpStatus.OK) :
new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
Run Code Online (Sandbox Code Playgroud)
服务:
@Transactional
public Optional<Foo> save(Foo foo){
foo = fooRepository.save(foo);
publisher.publishEvent(new FooEvent(foo));
return Optional.of(foo);
}
Run Code Online (Sandbox Code Playgroud)
上面的方法没有@Transcational,下面的方法不会被触发。
聆听者
@Async
@TransactionalEventListener(condition ="#event.ok", phase = TransactionPhase.AFTER_COMMIT)
public void handle(FooEvent event){
Product product = new Product(event.getData());
productService.save(product);
}
Run Code Online (Sandbox Code Playgroud)
产品服务
@Transactional(propagation = Propagation.REQUIRES_NEW)
public Optional<Product> save(Product product){
product = productRepository.save(product);
return Optional.of(product);
}
Run Code Online (Sandbox Code Playgroud)
尽管调用了侦听器方法,但根本不会保存 Product 数据。代码在 …
我将 jib 添加到 pom.xml 文件中,如下所示:
<properties>
<docker.org>springcloudstream</docker.org>
<docker.version>${project.version}</docker.version>
</properties>
...
<build>
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>2.1.0</version>
<configuration>
<from>
<image>springcloud/openjdk</image>
</from>
<to>
<image>${docker.org}/${project.artifactId}:${docker.version}</image>
</to>
<container>
<useCurrentTimestamp>true</useCurrentTimestamp>
</container>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
运行以下构建命令后,
./mvnw package jib:dockerBuild
Run Code Online (Sandbox Code Playgroud)
我收到以下错误。
[ERROR] Failed to execute goal com.google.cloud.tools:jib-maven-plugin:2.1.0:dockerBuild (default-cli) on project usage-detail-sender-kafka: Unable to parse configuration of mojo com.google.cloud.tools:jib-maven-plugin:2.1.0:dockerBuild for parameter useCurrentTimestamp: Cannot find 'useCurrentTimestamp' in class com.google.cloud.tools.jib.maven.JibPluginConfiguration$ContainerParameters
Run Code Online (Sandbox Code Playgroud)
UseCurrentTimestamp 已在配置中。经过网上搜索,我只找到一个条目: https: //github.com/GoogleContainerTools/jib/issues/413。我在页面上看不到解决方案。
缺什么?
按照此说明,我尝试将前端应用程序部署到Google Cloud.在最后一步,我收到命令"gcloud app deploy"的以下错误
(gcloud.app.deploy) Unable to deploy to application [my-app] with status [USER_DISABLED]: Deploying to stopped apps is not allowed.
Run Code Online (Sandbox Code Playgroud)
我查看了我的Google Cloud帐户,但无法找到已停用的状态.
我应该在哪里解决这个问题?
spring-boot ×2
git ×1
github ×1
jib ×1
kubernetes ×1
openapi ×1
spring ×1
spring-data ×1
swagger ×1