我输入了"root"密码,它不断弹出.我怎么能抑制它或摆脱它.我正在使用弹簧靴和弹簧安全.
application.properties
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/springbootpractice
spring.datasource.username=root
spring.jpa.database = MYSQL
spring.jpa.show-sql = true
# Hibernate
hibernate.dialect: org.hibernate.dialect.MySQL5Dialect
hibernate.show_sql: true
hibernate.hbm2ddl.auto: update
entitymanager.packagesToScan: /
Run Code Online (Sandbox Code Playgroud)
如果重要的话,我正在使用intellij 14.
----更新1 -----
@Configuration
@EnableWebMvcSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "/index").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/index")
.permitAll()
.and()
.logout()
.permitAll();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "/index").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/index")
.permitAll()
.and()
.logout()
.permitAll();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) …Run Code Online (Sandbox Code Playgroud) 是否可以以编程方式编辑本机Google文档,比如说某些单词是粗体还是超链接?我知道我可以将其导出为某种格式,如DOC或ODT,进行更改并放回去.但手动尝试这种方式,看到我失去了确切的外观.无法找到本机Google文档的任何API或对象模型,尽管电子表格似乎有些东西.
我有一个使用Spring Data JPA的Spring Boot 1.3.M1 Web应用程序.对于乐观锁定,我正在做以下事情:
@Version private long version;.通过查看数据库表,我确认该字段正在递增.version也会发送该字段.version字段作为隐藏字段或其他内容接收.服务器端,获取实体的新副本,然后更新所需字段以及version字段.像这样:
User user = userRepository.findOne(id);
user.setName(updatedUser.getName());
user.setVersion(updatedUser.getVersion());
userRepository.save(user);
Run Code Online (Sandbox Code Playgroud)我希望在版本不匹配时抛出异常.但事实并非如此.谷歌搜索,我发现一些帖子说我们不能设置@Vesion附加实体的属性,就像我在上面的第三个语句中所做的那样.
所以,我猜我必须手动检查版本不匹配并自己抛出异常.这是正确的方法,还是我错过了什么?
我正在尝试使用 Spring Security 5 OAuth2 登录功能让 Google/Facebook 登录。但我面临的问题是我正在编写一个无状态 API,而 Spring security 5 用于HttpSessionOAuth2AuthorizationRequestRepository存储授权请求,它使用会话。因此,我认为不要使用它并编写基于 cookie 的实现,如下所示:
public class HttpCookieOAuth2AuthorizationRequestRepository implements AuthorizationRequestRepository<OAuth2AuthorizationRequest> {
private static final String COOKIE_NAME = "some-name";
@Override
public OAuth2AuthorizationRequest loadAuthorizationRequest(HttpServletRequest request) {
Assert.notNull(request, "request cannot be null");
return fetchCookie(request)
.map(this::toOAuth2AuthorizationRequest)
.orElse(null);
}
@Override
public void saveAuthorizationRequest(OAuth2AuthorizationRequest authorizationRequest, HttpServletRequest request,
HttpServletResponse response) {
Assert.notNull(request, "request cannot be null");
Assert.notNull(response, "response cannot be null");
if (authorizationRequest == null) {
deleteCookie(request, response);
return;
}
Cookie cookie = new Cookie(COOKIE_NAME, …Run Code Online (Sandbox Code Playgroud) 在 Spring MVC 中,我有一个@UniqueEmail自定义的休眠验证器(用于在注册时检查电子邮件的唯一性),如下所示:
public class UniqueEmailValidator
implements ConstraintValidator<UniqueEmail, String> {
private UserRepository userRepository;
public UniqueEmailValidator(UserRepository userRepository) {
this.userRepository = userRepository;
}
@Override
public boolean isValid(String email, ConstraintValidatorContext context) {
return !userRepository.findByEmail(email).isPresent();
}
}
Run Code Online (Sandbox Code Playgroud)
现在我正在使用反应式 MongoDB 迁移到 WebFlux,代码如下:
public class UniqueEmailValidator
implements ConstraintValidator<UniqueEmail, String> {
private MongoUserRepository userRepository;
public UniqueEmailValidator(MongoUserRepository userRepository) {
this.userRepository = userRepository;
}
@Override
public boolean isValid(String email, ConstraintValidatorContext context) {
return userRepository.findByEmail(email).block() == null;
}
}
Run Code Online (Sandbox Code Playgroud)
首先,block像上面那样使用看起来不太好。其次,它不起作用,这是错误:
Caused by: java.lang.IllegalStateException: block()/blockFirst()/blockLast() are …Run Code Online (Sandbox Code Playgroud) 我正在考虑开发这样的应用程序:
为此,我的应用程序需要唯一标识与其共享的文档的所有者。我查看了 API,但找不到如何操作。我找到了像File.getOwnerNames()这样的方法,但它们是包含名称的纯字符串,但没有任何用于识别用户的唯一键。
需要有关如何实现这一目标的帮助。谢谢。
桑杰
我是 AngularJS 的新手。无法找到一种方法将几个li项目一起包含在一个ng-if. Knockout 有虚拟元素来完成这些工作,就像这样
<ul>
<li>This item always appears</li>
<!-- ko if: someExpressionGoesHere -->
<li>I want to make this item present/absent dynamically</li>
<li>I want to make this item present/absent dynamically</li>
<!-- /ko -->
</ul>
Run Code Online (Sandbox Code Playgroud)
将不胜感激帮助。
更新:在引导程序的导航中使用时,将其封闭在容器内,例如<div>or<span>会扭曲视图:
<div ng-if="!auth.user">
<li>
<a href="#!/signup">Sign up <span class="glyphicon glyphicon-list-alt"></span></a>
</li>
<li>
<a href="#!/login">Sign in <span class="glyphicon glyphicon-log-in"></span></a>
</li>
</div>
Run Code Online (Sandbox Code Playgroud)
桑杰
在我的一个Spring应用程序中,我计划MethodValidationPostProcessor用于验证服务方法参数.据我所知,为此,我必须MethodValidationPostProcessor在ApplicationContext中有一个对象,而后者必须validator注入一个对象.我在@Configuration课堂上这样做:
@Bean
public LocalValidatorFactoryBean validator() {
return new LocalValidatorFactoryBean();
}
@Bean
public MethodValidationPostProcessor getMethodValidationPostProcessor(){
MethodValidationPostProcessor processor = new MethodValidationPostProcessor();
processor.setValidator(validator());
return processor;
}
Run Code Online (Sandbox Code Playgroud)
然后,我的服务类看起来像这样:
@Service
@Validated
public class SomeService {
public void someMethod(@Valid SomeForm someForm) {
.
.
.
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我的一些对象需要一些自定义验证器.例如,对于注册表单,我打算使用JoinDataValidator扩展LocalValidatorFactoryBean,如下所示:
@Service("joinDataValidator")
public class JoinDataValidator extends LocalValidatorFactoryBean {
@Override
public void validate(final Object target, final Errors errors) {
super.validate(target, errors);
// check for duplicate email
}
@Override …Run Code Online (Sandbox Code Playgroud) 对于具有global @ModelAttribute,我正在使用@ControllerAdvice,例如:
@ControllerAdvice
public class MyControllerAdvice {
@ModelAttribute("globalModelAttribute")
public String getFacebookScope() {
return "FACEBOOK_SCOPE";
}
}
Run Code Online (Sandbox Code Playgroud)
现在,globalModelAttribute除了已注册为ViewController的JSP之外,我现在可以访问其所有JSP中的,如下所示:
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("home");
registry.addViewController("/login").setViewName("login");
}
}
Run Code Online (Sandbox Code Playgroud)
想知道如何去做。
我正在开发一个基于Spring Boot的库,它可以在多个Spring Boot应用程序中使用.该库应该与Spring Boot一起使用1.3.0.M1.
我在想如何避免在其中放入特定版本的Spring JAR,而是让应用程序指定确切的版本.目前我已经推出了这个解决方案,除了某些组合之外似乎有效:
在库中,将Spring Boot版本作为1.3.0.M1,并具有所有依赖项的范围provided.像这样:
...
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.0.M1</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<scope>provided</scope>
</dependency>
...
Run Code Online (Sandbox Code Playgroud)在应用程序中,提及实际的Spring Boot版本,例如1.3.0.M3,并重新包含所有依赖项,如下所示:
...
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.0.M3</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
...
Run Code Online (Sandbox Code Playgroud)当我使用这个1.3.0.M1+ 1.3.0.M3特定组合运行应用程序时,我收到此错误,我认为这只是一些兼容性问题:
Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.core.ResolvableType.forInstance(Ljava/lang/Object;)Lorg/springframework/core/ResolvableType;
Run Code Online (Sandbox Code Playgroud)
但是,尝试使用稳定版本,例如,当我将lib版本设置为1.2.0.RELEASE和应用程序版本时1.2.5.RELEASE,它可以工作.
所以,我想知道这是否是处理这种情况的正确方法,或者有更好的方法.