【未解决】spring security 有时不会注入 Principal ? 问题: 已经的 filter 中写入了 SecurityContextHolder.getContext().setAuthentication(auth); 1 SecurityContextHolder.getContext().setAuthentication(auth); 但是… Read More
【未解决】Spring JPA 竟然自动保存 问题: Java @Service public class T1Service { @Autowired T1Repo t1Repo; @Transactional public void test(int id) { T1 t1 = t1Repo.getOne(id); t1.setName("tt" + new Date()); } } 1234567891011 @Servicepublic class T1Service { @Autowired T1Repo t1Repo; @Transactional public void test(int id) { T1 t1 = t1Repo.getOne(id); t1.setName("tt" + new Date()); }} 虽然没有 t1Repo… Read More
spring data jpa @Onetoone 出现了 1+n query 问题 Issue. article 是 @OneToOne 但是 取 issue.article 时还会去se… Read More
apache client https 禁止证书检测 解决: /** * 绕过验证 * * @return * @throws NoSuchAlgorithmException * @throws KeyManagementException */ static SSLContext createIgnoreVerifySSL() throws NoSuchAlgorithmException, KeyManagementException { SSLContext sc = SSLContext.getInstance("SSLv3"); // 实现一个X509TrustManager接口,用于绕过验证,不用修改里面的方法 X509TrustManager trustManager = new X509TrustManager() { @Override public void checkClientTrusted( java.security.cert.X509Certificate[] paramArrayOfX509Certificate, String paramString) throws CertificateException { } @Override public void checkServerTrusted( java.security.cert.X509Certificate[] paramArrayOfX509Certificate, String paramString) throws CertificateException { } @Override public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } }; sc.init(null, new TrustManager[]{trustManager}, null); return sc; } public static CloseableHttpClient ignoreSSLClient() throws KeyManagementException, NoSuchAlgorithmException { //采用绕过验证的方式处理https请求 SSLContext sslcontext = HttpUtils.createIgnoreVerifySSL(); //设置协议http和https对应的处理socket链接工厂的对象 Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.INSTANCE) .register("https", new SSLConnectionSocketFactory(sslcontext)) .build(); PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry); HttpClients.custom().setConnectionManager(connManager); //创建自定义的httpclient对象 CloseableHttpClient client = HttpClients.custom().setConnectionManager(connManager).build(); return client; } 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 /** * 绕过验证 * * @return * @throws NoSuchAlgorithmException * @throws KeyManagementException */ static SSLContext createIgnoreVerifySSL() throws NoSuchAlgorithmException, KeyManagementException { SSLContext sc = SSLContext.getInstance("SSLv3"); // 实现一个X509TrustManager接口,用于绕过验证,不用修改里面的方法 X509TrustManager trustManager = new X509TrustManager() { @Override public void checkClientTrusted( java.security.cert.X509Certificate[] paramArrayOfX509Certificate, String paramString) throws CertificateException { } @Override public void checkServerTrusted( java.security.cert.X509Certificate[] paramArrayOfX509Certificate, String paramString) throws CertificateException { } @Override public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } }; sc.init(null, new TrustManager[]{trustManager}, null); return sc; } public static CloseableHttpClient ignoreSSLClient() throws KeyManagementException, NoSuchAlgorithmException {//采用绕过验证的方式处理https请求 SSLContext sslcontext = HttpUtils.createIgnoreVerifySSL(); //设置协议http和https对应的处理socket链接工厂的对象 Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.INSTANCE) .register("https", new SSLConnectionSocketFactory(sslcontext)) .build(); PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry); HttpClients.custom().setConnectionManager(connManager); //创建自定义的httpclient对象 CloseableHttpClient client = HttpClients.custom().setConnectionManager(connManager).build(); return client; } &nbs… Read More
private static enum StoreFieldSetMapper implements FieldSetMapper 这种写法少见呢 /* * Copyright 2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package example.stores; import java.util.ArrayList; import java.util.List; import java.util.Scanner; import lombok.extern.slf4j.Slf4j; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.file.FlatFileItemReader; import org.springframework.batch.item.file.mapping.DefaultLineMapper; import org.springframework.batch.item.file.mapping.FieldSetMapper; import org.springframework.batch.item.file.separator.DefaultRecordSeparatorPolicy; import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; import org.springframework.batch.item.file.transform.FieldSet; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import org.springframework.data.geo.Point; import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.stereotype.Component; import org.springframework.validation.BindException; /** * Component initializing a hand full of Starbucks stores and persisting them through a {@link StoreRepository}. * * @author Oliver Gierke */ @Slf4j @Component public class StoreInitializer { @Autowired public StoreInitializer(StoreRepository repository) throws Exception { if (repository.count() != 0) { return; } List<Store> stores = readStores(); log.info("Importing {} stores into MongoDB…", stores.size()); repository.saveAll(stores); log.info("Successfully imported {} stores.", repository.count()); } /** * Reads a file {@code starbucks.csv} from the class path and parses it into {@link Store} instances about to * persisted. * * @return * @throws Exception */ public static List<Store> readStores() throws Exception { ClassPathResource resource = new ClassPathResource("starbucks.csv"); Scanner scanner = new Scanner(resource.getInputStream()); String line = scanner.nextLine(); scanner.close(); FlatFileItemReader<Store> itemReader = new FlatFileItemReader<Store>(); itemReader.setResource(resource); // DelimitedLineTokenizer defaults to comma as its delimiter DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer(); tokenizer.setNames(line.split(",")); tokenizer.setStrict(false); DefaultLineMapper<Store> lineMapper = new DefaultLineMapper<Store>(); lineMapper.setLineTokenizer(tokenizer); lineMapper.setFieldSetMapper(StoreFieldSetMapper.INSTANCE); itemReader.setLineMapper(lineMapper); itemReader.setRecordSeparatorPolicy(new DefaultRecordSeparatorPolicy()); itemReader.setLinesToSkip(1); itemReader.open(new ExecutionContext()); List<Store> stores = new ArrayList<>(); Store store = null; do { store = itemReader.read(); if (store != null) { stores.add(store); } } while (store != null); return stores; } private static enum StoreFieldSetMapper implements FieldSetMapper<Store> { INSTANCE; /* * (non-Javadoc) * @see org.springframework.batch.item.file.mapping.FieldSetMapper#mapFieldSet(org.springframework.batch.item.file.transform.FieldSet) */ @Override public Store mapFieldSet(FieldSet fields) throws BindException { Point location = new Point(fields.readDouble("Longitude"), fields.readDouble("Latitude")); Address address = new Address(fields.readString("Street Address"), fields.readString("City"), fields.readString("Zip"), location); return new Store(fields.readString("Name"), address); } } } 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 /* * Copyright 2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package example.stores; import java.util.ArrayList;import java.util.List;import java.util.Scanner; import lombok.extern.slf4j.Slf4j; import org.springframework.batch.item.ExecutionContext;import org.springframework.batch.item.file.FlatFileItemReader;import org.springframework.batch.item.file.mapping.DefaultLineMapper;import org.springframework.batch.item.file.mapping.FieldSetMapper;import org.springframework.batch.item.file.separator.DefaultRecordSeparatorPolicy;import org.springframework.batch.item.file.transform.DelimitedLineTokenizer;import org.springframework.batch.item.file.transform.FieldSet;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.core.io.ClassPathResource;import org.springframework.data.geo.Point;import org.springframework.data.mongodb.core.MongoOperations;import org.springframework.stereotype.Component;import org.springframework.validation.BindException; /** * Component initializing a hand full of Starbucks stores and persisting them through a {@link StoreRepository}. * * @author Oliver Gierke */@Slf4j@Componentpublic class StoreInitializer { @Autowired public StoreInitializer(StoreRepository repository) throws Exception { if (repository.count() != 0) { return; } List<Store> stores = readStores(); log.info("Importing {} stores into MongoDB…", stores.size()); repository.saveAll(stores); log.info("Successfully imported {} stores.", repository.count()); } /** * Reads a file {@code starbucks.csv} from the class path and parses it into {@link Store} instances about to * persisted. * * @return * @throws Exception */ public static List<Store> readStores() throws Exception { ClassPathResource resource = new ClassPathResource("starbucks.csv"); Scanner scanner = new Scanner(resource.getInputStream()); String line = scanner.nextLine(); scanner.close(); FlatFileItemReader<Store> itemReader = new FlatFileItemReader<Store>(); itemReader.setResource(resource); // DelimitedLineTokenizer defaults to comma as its delimiter DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer(); tokenizer.setNames(line.split(",")); tokenizer.setStrict(false); DefaultLineMapper<Store> lineMapper = new DefaultLineMapper<Store>(); lineMapper.setLineTokenizer(tokenizer); lineMapper.setFieldSetMapper(StoreFieldSetMapper.INSTANCE); itemReader.setLineMapper(lineMapper); itemReader.setRecordSeparatorPolicy(new DefaultRecordSeparatorPolicy()); itemReader.setLinesToSkip(1); itemReader.open(new ExecutionContext()); List<Store> stores = new ArrayList<>(); Store store = null; do { store = itemReader.read(); if (store != null) { stores.add(store); } } while (store != null); return stores; } private static enum StoreFieldSetMapper implements FieldSetMapper<Store> { INSTANCE; /* * (non-Javadoc) * @see org.springframework.batch.item.file.mapping.FieldSetMapper#mapFieldSet(org.springframework.batch.item.file.transform.FieldSet) */ @Override public Store mapFieldSet(FieldSet fields) throws BindException { Point location = new Point(fields.readDouble("Longitude"), fields.readDouble("Latitude")); Address address = new Address(fields.readString("Street Address"), fields.readString("City"), fields.readString("Zip"), location); return new Store(fields.readString("Name"), address); } }} &… Read More
【未解决】springboot bean init-method 不灵光呢 问题: 下列代码不会调用 init 方法 @Component //@RequestScope @Scope(scopeName = "prototype", proxyMode = ScopedProxyMode.TARGET_CLASS) public class RequestOpContext implements InitializingBean { int i = 0; public RequestOpContext(){ System.out.println("RequestOpContext()"); } public void init(){ System.out.println("init"); i=10; } public int getId(){ return i; } @Override public void afterPropertiesSet() throws Exception { init(); } } 1234567891011121314151617181920212223 @Component//@RequestScope@Scope(scopeName = "prototype", proxyMode = ScopedProxyMode.TARGET_CLASS)public class RequestOpContext implements InitializingBean { int i = 0; public RequestOpContext(){ System.out.println("RequestOpContext()"); } public void init(){ System.out.println("init"); i=10; } public int getId(){ return i; } @Override public void afterPropertiesSet() throws Exception { init(); }} &… Read More
JDK11.0.3 module java.base does not “opens jdk.internal.reflect” to unnamed module @4f757cf6 问题: JDK11.0.3 报错,11.0.2 还正常 Caused by: java.lang.reflec… Read More