Spring Setter注入(Setter injection)和构造注入(Constructor injection)
平时使用Spring少不了各种注入,大部分时候都是直接在属性上@Autowired就完了,偶尔看到在构造方法上注入的也知道怎么回事。今天忽然想到这俩有什么区别,了解了下使用场景。
平时使用Spring少不了各种注入,大部分时候都是直接在属性上@Autowired就完了,偶尔看到在构造方法上注入的也知道怎么回事。今天忽然想到这俩有什么区别,了解了下使用场景。
在使用lambda的map时候看到了flatMap这个方法,之前知道和map不一样,但是一直没管它,这次又想起来,就找了点资料看了下。
在使用Notepad++转换编码时,转为UTF-8可以选择“UTF-8”和“UTF-8 BOM”这两种,有点好奇这俩有什么区别,于是查了会资料。
用了spring-boot-starter-data-mongodb模块后,连接本机的Mongodb一直失败,用户也创建了,密码也设了,就是连不上啊。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
总是报错:
com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=null, userName='test', source='test', password=<hidden>, mechanismProperties={}}
at com.mongodb.connection.SaslAuthenticator.wrapException(SaslAuthenticator.java:162)
at com.mongodb.connection.SaslAuthenticator.access$200(SaslAuthenticator.java:39)
at com.mongodb.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:68)
at com.mongodb.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:46)
at com.mongodb.connection.SaslAuthenticator.doAsSubject(SaslAuthenticator.java:168)
at com.mongodb.connection.SaslAuthenticator.authenticate(SaslAuthenticator.java:46)
at com.mongodb.connection.DefaultAuthenticator.authenticate(DefaultAuthenticator.java:32)
at com.mongodb.connection.InternalStreamConnectionInitializer.authenticateAll(InternalStreamConnectionInitializer.java:122)
at com.mongodb.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:52)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:127)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:114)
at java.lang.Thread.run(Thread.java:748)
Caused by: com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server localhost:27017. The full response is { "ok" : 0.0, "errmsg" : "Authentication failed.", "code" : 18, "codeName" : "AuthenticationFailed" }
at com.mongodb.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:164)
at com.mongodb.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:295)
at com.mongodb.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:255)
at com.mongodb.connection.CommandHelper.sendAndReceive(CommandHelper.java:84)
at com.mongodb.connection.CommandHelper.executeCommand(CommandHelper.java:34)
at com.mongodb.connection.SaslAuthenticator.sendSaslContinue(SaslAuthenticator.java:123)
at com.mongodb.connection.SaslAuthenticator.access$100(SaslAuthenticator.java:39)
at com.mongodb.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:65)
... 9 common frames omitted
已经有很多人吐槽过这个设置了,搜索过的历史有多少人会在去搜?而且这玩意之前还能通过chrome://flags
关闭,更新到86版本后直接就不让关了,脑残Google?真就为所欲为。