这个例子在C#中,但问题确实适用于任何OO语言.我想创建一个实现IReadOnlyList的通用不可变类.此外,此类应具有无法修改的基础通用IList.最初,该课程编写如下:
public class Datum<T> : IReadOnlyList<T>
{
private IList<T> objects;
public int Count
{
get;
private set;
}
public T this[int i]
{
get
{
return objects[i];
}
private set
{
this.objects[i] = value;
}
}
public Datum(IList<T> obj)
{
this.objects = obj;
this.Count = obj.Count;
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
public IEnumerator<T> GetEnumerator()
{
return this.objects.GetEnumerator();
}
}
Run Code Online (Sandbox Code Playgroud)
但是,这不是一成不变的.正如您可能知道的那样,更改初始IList'obj'会更改Datum的'对象'.
static void Main(string[] args)
{
List<object> list = new List<object>();
list.Add("one");
Datum<object> datum = new Datum<object>(list);
list[0] = …Run Code Online (Sandbox Code Playgroud) 我们的应用程序使用亚马逊的 SQS 作为消息队列,我们使用 elasticMQ 进行测试/登台;elasticMQ 是一个完全兼容 SQS 的消息队列服务器。由于我们的大部分应用程序是在 Java 中,我们可以在我们的测试或暂存中运行嵌入式 elasticMQ,切换我们的队列端点以指向 elasticMQ 和瞧,一切都运行得非常好,我们不接触我们的生产队列。
话虽如此,我们的一些应用程序是用 python 编写的——它使用 boto3 来处理 SQS 请求。由于 elasticMQ 也可以作为独立应用程序运行,我想知道是否可以将端点从默认 url (sqs.region.amazonaws.com:80) 切换到 boto3 中的其他内容 (localhost:9324)。我已经搜索了文档和 SO,但无法确定我想做的事情是否可行。
我有一个非常简单的 spring 数据 cassandra 项目,其应用程序上下文无法启动。整个项目由四个文件组成:域对象、存储库接口、cassandra 配置和应用程序入口点。这是域对象:
@Table
public class User {
@PrimaryKeyColumn(name = "user_id", ordinal = 0, type = PrimaryKeyType.PARTITIONED)
public UUID userId;
}
Run Code Online (Sandbox Code Playgroud)
和存储库界面:
@Repository
public interface UserRepository extends PagingAndSortingRepository<User, UUID> {
}
Run Code Online (Sandbox Code Playgroud)
配置非常简单:
@Configuration
public class TestSpringDataCassandraConfiguration extends AbstractCassandraConfiguration {
@Override
protected String getKeyspaceName() {
return "company";
}
@Override
protected List<CreateKeyspaceSpecification> getKeyspaceCreations() {
return Collections.singletonList(CreateKeyspaceSpecification
.createKeyspace(getKeyspaceName())
.ifNotExists()
.withSimpleReplication(1));
}
@Override
public String[] getEntityBasePackages() {
return new String[] { "com.company.project.cassandra.entity"};
}
@Override
public SchemaAction getSchemaAction() {
return SchemaAction.CREATE_IF_NOT_EXISTS;
} …Run Code Online (Sandbox Code Playgroud) spring cassandra spring-data spring-boot spring-data-cassandra
我有一个超类,它包含组件的通用功能.
export class AbstractComponent implements OnInit {
public user: User;
constructor(public http: HttpClient) {
}
ngOnInit(): void {
this.http.get<User>('url').subscribe(user => {
this.user = user;
});
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个实现这个超类的子类.
@Component({
selector: 'app-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.scss']
})
export class HeaderComponent extends AbstractComponent {
constructor(public http: HttpClient) {
super(http);
}
}
Run Code Online (Sandbox Code Playgroud)
在标题模板中,我试图访问用户
<mat-toolbar color="primary">
<span *ngIf="user">Welcome {{user.username}}!</span>
</mat-toolbar>
Run Code Online (Sandbox Code Playgroud)
但是用户字段没有得到解决.如何从子类访问超类的字段?
我有一个已更新为包含新字段的架构。我正在使用avro反射和融合的架构注册表来反序列化/序列化数据,如下所示:
序列化:
Schema schema = REFLECT_DATA.getSchema(value.getClass());
try {
int registeredSchemaId = this.schemaRegistry.register(subject, schema);
ByteArrayOutputStream out = new ByteArrayOutputStream();
out.write(0);
out.write(ByteBuffer.allocate(4).putInt(registeredSchemaId).array());
DatumWriter<Object> dw = new ReflectDatumWriter<>(schema);
Encoder encoder = ENCODER_FACTORY.directBinaryEncoder(out, null);
dw.write(value, encoder);
encoder.flush();
return out.toByteArray();
} catch (RuntimeException | IOException e) {
throw new SerializationException("Error serializing Avro message", e);
} catch (RestClientException e) {
throw new SerializationException("Error registering Avro schema: " + schema, e);
}
Run Code Online (Sandbox Code Playgroud)
反序列化:
if (readerSchema == null) {
readerSchema = new Schema.Parser().parse(schemaString);
}
int schemaId = -1; …Run Code Online (Sandbox Code Playgroud) 我有一个简单的方法AuthenticationEntryPoint,它应该为未经授权的请求设置 WWW-Authenticate 标头。
@Component
public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint {
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException)
throws IOException, ServletException {
response.setHeader("WWW-Authenticate", "FormBased");
response.sendError(401, authException.getMessage());
}
}
Run Code Online (Sandbox Code Playgroud)
我在以下配置方法之一中使用它 AuthorizationServerConfigurer
@Override
public void configure(AuthorizationServerSecurityConfigurer authorizationServerSecurityConfigurer) throws Exception {
authorizationServerSecurityConfigurer.authenticationEntryPoint(authenticationEntryPoint);
}
Run Code Online (Sandbox Code Playgroud)
但是,并不总是调用此开始方法。当请求中没有 Authorize 标头或 Authorize 标头值不以“Basic”开头时,它会被调用。但是,如果 Authorize 标头以“Basic”开头,则不会调用开始方法(并且响应的值为Basic realm="oauth2/client")。如何确保调用此方法?
java authentication spring spring-security spring-security-oauth2
我们正在尝试提交一个火花工作(火花2.0,hadoop 2.7.2),但由于某种原因,我们在EMR中收到了相当神秘的NPE.一切都像scala程序一样运行,所以我们不确定是什么导致了这个问题.这是堆栈跟踪:
18:02:55,271 ERROR Utils:91 - 在org.apache.spark.sql.catalyst的org.apache.spark.sql.catalyst.expressions.GeneratedClass $ GeneratedIterator.agg_doAggregateWithKeys $(未知来源)中止任务java.lang.NullPointerException .expressions.GeneratedClass $ GeneratedIterator.processNext(未知来源)org.apache.spark.sql.execution.BufferedRowIterator.hasNext(BufferedRowIterator.java:43)org.apache.spark.sql.execution.WholeStageCodegenExec $$ anonfun $ 8 $ $ anon $ 1.hasNext(WholeStageCodegenExec.scala:370)at scala.collection.Iterator $$ anon $ 12.hasNext(Iterator.scala:438)at org.apache.spark.sql.execution.datasources.DefaultWriterContainer $$ anonfun $ writeRows $ 1.apply $ mcV $ sp(WriterContainer.scala:253)位于org.apache.spark的org.apache.spark.sql.execution.datasources.DefaultWriterContainer $$ anonfun $ writeRows $ 1.apply(WriterContainer.scala:252). sql.execution.datasources.DefaultWriterContainer $$ anonfun $ writeRows $ 1.apply(WriterContainer.scala:252)at org.apache.spark.util.Utils $ .tryWithSafeFinallyA ndFailureCallbacks(Utils.scala:1325)org.apache.spark.sql.execution.datasources.DefaultWriterContainer.writeRows(WriterContainer.scala:258)at org.apache.spark.sql.execution.datasources.InsertIntoHadoopFsRelationCommand $$ anonfun $ run $ 1 $$ anonfun $应用$ mcV $ sp $ 1.apply(InsertIntoHadoopFsRelationCommand.scala:143)在org.apache.spark.sql.execution.datasources.InsertIntoHadoopFsRelationCommand $$ anonfun $ run $ 1 $$ anonfun $ apply …
我有以下列族:
@Table(value = "request_event")
public class RequestEvent {
@PrimaryKeyColumn(name = "day_requested", ordinal = 0, type = PrimaryKeyType.PARTITIONED)
private LocalDate dayRequested;
@PrimaryKeyColumn(name = "date_requested", ordinal = 1, type = PrimaryKeyType.CLUSTERED, ordering = Ordering.DESCENDING)
private LocalDateTime dateRequested;
...
}
Run Code Online (Sandbox Code Playgroud)
由存储库存储和访问:
@Repository
public interface RequestEventRepository extends CrudRepository<RequestEvent, LocalDateTime> {
}
Run Code Online (Sandbox Code Playgroud)
不幸的requestEventRepository.findOne(localDate)是抛出异常,可能是因为它返回了多个结果.我怎样才能解决这个问题?此外,如何检索特定日期的所有结果?
我试图排除某些类被包含在阴影 jar 中。
我尝试了几种不同的配置,但由于某种原因,罐子仍然包含在我的罐子中。这是插件设置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>java/*</exclude>
</excludes>
</filter>
</filters>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我还尝试了以下模式:
<exclude>java.*</exclude>
<exclude>java.util.concurrent.ConcurrentHashMap</exclude>
<exclude>java/util/concurrent/ConcurrentHashMap</exclude>
Run Code Online (Sandbox Code Playgroud)
其中没有一个实际上从我的 jar 中排除了该文件。如何从我的 jar 中排除这个类?
使用docker-compose,我试图在公共端口8080和私有端口9324上的sqs服务上运行我的API .API需要能够与sqs服务通信.为此,我设置了以下docker-compose.yml:
version: '2'
services:
api:
image: api
ports:
- "8080:8080"
sqs:
image: pakohan/elasticmq
Run Code Online (Sandbox Code Playgroud)
我尝试了几次迭代,包括为api添加一个链接别名:
links:
- "sqs:localhost"
Run Code Online (Sandbox Code Playgroud)
并暴露sqs的端口:
ports:
- "9324:9324"
Run Code Online (Sandbox Code Playgroud)
但似乎都不起作用.尝试与sqs服务通信时,API始终会收到连接拒绝错误.
当sqs端口公开暴露时,在docker之外运行的API能够正常通信(因此sqs服务正在初始化正确).
有没有人对如何解决这个问题有任何想法?
java ×4
spring ×3
cassandra ×2
scala ×2
spring-data ×2
amazon-sqs ×1
angular ×1
angular5 ×1
apache-spark ×1
avro ×1
bigdata ×1
boto3 ×1
c# ×1
docker ×1
elastic-mq ×1
generics ×1
hadoop ×1
immutability ×1
inheritance ×1
jar ×1
javascript ×1
maven ×1
python ×1
spring-boot ×1