我正在用Java学习MongoDB.我正在尝试使用Java驱动程序将数据插入MongoDB.我正在插入像MongoDB教程一样,每件事都很好.但是,如果我想插入一个变量,当我运行代码时,驱动程序会抛出这样的错误:
org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class io.github.ilkgunel.mongodb.Pojo.
Run Code Online (Sandbox Code Playgroud)
我在Stack Overflow中解决了这样的问题,但我无法理解任何事情,我找不到任何解决此错误的方法.我的代码如下.怎么能解决这个问题?
我正在使用此代码:
package io.github.ilkgunel.mongodb;
import org.bson.Document;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
public class MongoDBBasicUsage {
public static void main(String[] args) {
MongoClient mongoClient;
try {
Pojo pojo = new Pojo();
mongoClient = new MongoClient("localhost", 27017);
MongoDatabase database = mongoClient.getDatabase("MongoDB");
pojo.setId("1");
pojo.setName("ilkay");
pojo.setSurname("günel");
Document document = new Document();
document.put("person", pojo);
database.getCollection("Records").insertOne(document);
} catch (Exception e) {
System.err.println("Bir Hata …Run Code Online (Sandbox Code Playgroud) 我在 SOAP 请求中使用 String 类作为请求对象类型。
我需要禁用 JAXB 转义并编写如下代码:
@Bean
public Jaxb2Marshaller jaxb2Marshaller() {
Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
Map<String, Object> map = new HashMap<String, Object>();
map.put("jaxb.formatted.output", true);
jaxb2Marshaller.setPackagesToScan("packageName");
map.put("com.sun.xml.internal.bind.marshaller.CharacterEscapeHandler",
new CharacterEscapeHandler() {
@Override
public void escape(char[] ac, int i, int j, boolean flag,
Writer writer) throws IOException {
writer.write(ac, i, j);
}
});
jaxb2Marshaller.setMarshallerProperties(map);
return jaxb2Marshaller;
}
Run Code Online (Sandbox Code Playgroud)
但是,我认为 Spring 不接受 com.sun.xml.internal.bind.marshaller.CharacterEscapeHandler 属性来禁用字符转义。它给出这样的错误:
2022-01-07 19:39:41.124 ERROR 45808 --- [ter.container-1] c.p.d.g.s.SendMailService : org.springframework.oxm.UncategorizedMappingException: Unknown JAXB exception; nested exception is javax.xml.bind.PropertyException: name: com.sun.xml.internal.bind.marshaller.CharacterEscapeHandler …Run Code Online (Sandbox Code Playgroud) 我将 ShedLock 添加到我的项目中,以防止预定作业重复执行一次。我将其配置如下,但我得到了
“org.postgresql.util.PSQLException:错误:关系“shedlock”不存在”错误。
这是lockProviderBean:
@Bean
public LockProvider lockProvider(DataSource dataSource) {
return new JdbcTemplateLockProvider(
JdbcTemplateLockProvider.Configuration.builder()
.withJdbcTemplate(new JdbcTemplate(dataSource))
.usingDbTime()
.build()
);
}
Run Code Online (Sandbox Code Playgroud)
这是预定的工作:
@Scheduled(cron = "${cronProperty:0 00 23 * * *}")
@SchedulerLock(name = "schedulerLockName")
public void scheduledJob() {
..............
}
Run Code Online (Sandbox Code Playgroud)
我将这些符号添加到包含 schduledJob 方法的类中:
@EnableScheduling
@Component
@Configuration
@EnableSchedulerLock(defaultLockAtMostFor = "2m")
Run Code Online (Sandbox Code Playgroud)
我正在使用 Spring Data 进行数据库操作并使用这些属性:
spring.datasource.url = jdbc:postgresql://ip:port/databaseName?currentSchema=schemeName
spring.datasource.driver-class-name = org.postgresql.Driver
spring.jpa.database = postgresql
spring.datasource.platform = postgresql
spring.datasource.hikari.maximum-pool-size=5
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.datasource.username = username
spring.datasource.password = password
Run Code Online (Sandbox Code Playgroud) 我正在 Spring Rest 和我的 Spring Rest 应用程序中工作,如果我尝试生成 json 一切都可以。我可以在浏览器上看到它。没有错误。
\n\n但如果我想生成 XML,我可以使用 Produces = "application/xml" 或 Produces=MediaType.TEXT_XML_VALUE 并\n我收到此错误:
\n\nWhitelabel Error Page\n\nThis application has no explicit mapping for /error, so you are seeing this as a fallback.\n\nSun Oct 23 18:30:51 EEST 2016\nThere was an unexpected error (type=Not Acceptable, status=406).\nCould not find acceptable representation\nRun Code Online (Sandbox Code Playgroud)\n\n我的其余代码是:
\n\npackage getExample;\n\nimport java.util.ArrayList;\nimport java.util.List;\n\nimport org.springframework.http.MediaType;\nimport org.springframework.web.bind.annotation.RequestMapping;\nimport org.springframework.web.bind.annotation.RequestMethod;\nimport org.springframework.web.bind.annotation.RequestParam;\nimport org.springframework.web.bind.annotation.RestController;\n\nimport pojo.Address;\nimport pojo.Person;\n\n@RestController\npublic class GetExampleController {\n\n @RequestMapping(value = "getExample",method=RequestMethod.GET,produces=MediaType.TEXT_XML_VALUE)\n public List<Person> getExample1(@RequestParam(value = "personId", defaultValue = …Run Code Online (Sandbox Code Playgroud) 我有一个 Android 项目,它在我的测试环境中运行良好,并带有测试环境证书。现在,我必须将此应用程序连接到客户端的 UAT 环境而不是测试环境。从客户的网站上,我下载了公共证书并将其添加到 Android 应用程序中,并替换了测试环境证书。当我测试应用程序时,出现以下错误。
这个错误是什么意思?错误与服务器端配置有关吗?我应该将此证书添加到Android操作系统的可信证书中吗?
编辑:从客户端网站下载的证书是 CA 证书。不是自签名证书。
W/System.err: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
W/System.err: at com.android.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(ConscryptFileDescriptorSocket.java:236)
W/System.err: at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.kt:367)
W/System.err: at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.kt:325)
W/System.err: at okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:197)
W/System.err: at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:249)
W/System.err: at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:108)
W/System.err: at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:76)
W/System.err: at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:245)
W/System.err: at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
W/System.err: at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:96)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
W/System.err: at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
W/System.err: at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
W/System.err: at xbnvqqyqoxeynry.dxdxdd.intercept(Unknown Source:29)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
W/System.err: at xbnvqqyqoxeynry.xxxxdx.intercept(Unknown Source:4) …Run Code Online (Sandbox Code Playgroud) android ×1
certificate ×1
java ×1
jaxb ×1
mongodb ×1
rest ×1
shedlock ×1
spring ×1
spring-boot ×1