我正在尝试了解微服务。我想知道如何解决微服务架构中一对多/多对多关系的问题以及最佳实践是什么。假设我想将学生课程应用程序转换为学生服务,课程服务和学生服务对话转换为同一数据库中的学生表和课程服务对话课程表。
示例:学生可以注册许多课程,并且许多课程可以有许多学生(多对多关系)。我有 2 个微服务 微服务 1:学生服务 微服务 2:课程服务
学生服务有学生对象
@Entity
@Table(name = "STUDENT")
public class Student {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Column(name = "NAME")
private String name;
//@ManyToMany(fetch = FetchType.LAZY)
//@JoinTable(name = "STUDENT_COURSE", joinColumns = @JoinColumn(name = //"STUDENT_ID"), inverseJoinColumns = @JoinColumn(name = "COURSE_ID"))
// private List<Course> courses = new ArrayList<Course>();
}
Run Code Online (Sandbox Code Playgroud)
课程服务有课程对象
@Entity
@Table(name = "COURSE")
public class Course {
@Id
@Column(name = "ID")
private long id;
@Column(name = "COURSE_NAME")
private String name;
//@ManyToMany(mappedBy = "courses", fetch …
Run Code Online (Sandbox Code Playgroud) java architecture database-design microservices spring-cloud
我需要使用 sed 修改 my.json 文件中的第三行,如下所示。
如何用分配给 $username 的变量值替换正在变化的键值(此示例显示“group-1”)?
"name": "group-1",
Run Code Online (Sandbox Code Playgroud) 早上好,当我尝试注册或通过我的虚拟设备登录时出现此错误:
E/StorageHelpers: Failed to turn object into JSON java.lang.NullPointerException: Attempt to invoke virtual method 'org.json.JSONObject com.google.firebase.auth.internal.zzm.zzbf()' on a null object reference at com.google.firebase.auth.internal.zzz.zzi(Unknown Source) at com.google.firebase.auth.internal.zzz.zzg(Unknown Source) at com.google.firebase.auth.FirebaseAuth.zza(Unknown Source) at com.google.firebase.auth.FirebaseAuth$zza.zza(Unknown Source) at com.google.firebase.auth.api.internal.zzbq.zzaa(Unknown Source) at com.google.firebase.auth.api.internal.zzcy.zzal(Unknown Source) at com.google.firebase.auth.api.internal.zzcy.zza(Unknown Source) at com.google.firebase.auth.api.internal.zzdb.zza(Unknown Source) at com.google.firebase.auth.api.internal.zzci.dispatchTransaction(Unknown Source) at com.google.android.gms.internal.firebase_auth.zzb.onTransact(Unknown Source) at android.os.Binder.execTransact(Binder.java:453)
Run Code Online (Sandbox Code Playgroud)
虚拟设备是Xperia Z3 Android 6.0.1 API23
这是LoginActivity.java的代码:
mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
progressBar.setVisibility(View.GONE);
if (task.isSuccessful()) {
finish();
Intent intent = new Intent(LoginActivity.this, …
Run Code Online (Sandbox Code Playgroud) java android json nullpointerexception firebase-authentication
我想在sklearn中构建一个Pipeline并使用GridSearchCV测试不同的模型.
只是一个例子(请不要注意选择的特定型号):
reg = LogisticRegression()
proj1 = PCA(n_components=2)
proj2 = MDS()
proj3 = TSNE()
pipe = [('proj', proj1), ('reg' , reg)]
pipe = Pipeline(pipe)
param_grid = {
'reg__c': [0.01, 0.1, 1],
}
clf = GridSearchCV(pipe, param_grid = param_grid)
Run Code Online (Sandbox Code Playgroud)
在这里,如果我想尝试不同的模型来减少维数,我需要编写不同的管道并手动比较它们.有一个简单的方法吗?
我想出的一个解决方案是定义从基本估算器派生的我自己的类:
class Projection(BaseEstimator):
def __init__(self, est_name):
if est_name == "MDS":
self.model = MDS()
...
...
def fit_transform(self, X):
return self.model.fit_transform(X)
Run Code Online (Sandbox Code Playgroud)
我认为它会起作用,我只是创建一个Projection对象并将其传递给Pipeline,使用估算器的名称作为参数.
但对我来说,这种方式有点乱,不可扩展:每次我想比较不同的模型时,我都会定义新类.另外,为了继续这个解决方案,可以实现一个执行相同工作但具有任意模型集的类.这对我来说似乎过于复杂.
比较不同模型的最自然和pythonic方法是什么?
我遇到了很多,并最终决定找出正确的方法。如果我有一个声明方法的抽象父类,然后某些具体的子类在其实现中实现了真正的逻辑(并且显然使用了方法参数),但是某些子类不需要在该方法中执行任何操作(因此请不要使用方法参数)-无需执行任何操作的操作会在我的代码中生成虚假(在我看来)警告。
例如,如果我有一些类似的类:
abstract class Child {
constructor(protected name: string) {
connsole.log(name + " was just born.");
}
abstract tellThemToDoSomething(command: string);
}
class GoodChild extends Child {
constructor(name: string) { super(name); }
tellThemToDoSomething(command: string) {
console.log("I will do " + command);
}
}
class BadChild extends Child {
constructor(name: string) { super(name); }
tellThemToDoSomething(command: string) {
// bad children just ignore what their parents tell them
}
}
Run Code Online (Sandbox Code Playgroud)
然后,对于该BadChild
tellThemToDoSomethign()
方法中未使用的参数,我在WebStorm中收到了(TSLint?JSLint?WebStorm?)警告。
我知道一些选择,但似乎都没有。
1)忽略它(但这似乎不是最理想的,因为我将对真正的警告视而不见)
2)从BadChild的方法实现中删除参数(但是不幸的是,它删除了有用的信息,因为稍后我可能要实现它,并且那里没有签名会增加它的难度,并且我还从调用者那里得到了错误,他们期望那里有参数-尽管考虑到我应该能够在JavaScript中调用带有无关参数的方法,但还是可以解决该问题)
3)告诉WebStorm(TSLint)停止对未使用的参数发出警告(但这似乎不是最优的,因为在其他实际问题情况下我不会收到警告)
4)对参数做一些毫无意义的事情,以使它不被使用(显然不是很好)
有经验的Java / TypeScript编码人员在这种情况下会做什么?有没有一种简单的方法可以告诉WebStorm / …
(读取字符串"01")返回1.
事实上,从"01"到"07"的读取字符串返回正确的答案.但是当我们这样做时(读取字符串"08")它会抛出一个错误:
NumberFormatException无效数字:08 clojure.lang.LispReader.readNumber(LispReader.java:330).
有人可以帮我弄明白为什么吗?"
我使用谷歌材料设计作为这个https://material.io/develop/android/docs/getting-started/但是当同步项目我有以下错误
在'android'包中找不到属性'appComponentFactory'的资源标识符消息{kind = ERROR,text =在'android'包中找不到属性'appComponentFactory'的资源标识符,sources = [\?\ E:\ Projects\xoxo- android\app\build\intermediates\manifests\full\debug\AndroidManifest.xml:17],原始消息=,工具名称= Optional.of(AAPT)}
这是我的build.gradle文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.example.official2.xoxo"
minSdkVersion 17
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.0.1'
compile 'org.apache.httpcomponents:httpclient:4.5'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'com.android.support:design:26.0.1'
compile 'com.google.android.gms:play-services-appindexing:8.1.0'
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4'
compile …
Run Code Online (Sandbox Code Playgroud) 我试图写一个通用的功能,这将尝试将字符串转换为数字类型一样i32
,f64
等等.如果字符串是不可自由兑换,然后将返回0
.我正在寻找一个适合在我的通用函数中使用的特性:
use std::str::FromStr;
fn get_num_from_str<T: FromStr>(maybe_num_str: &String) -> T {
let maybe_num = T::from_str(maybe_num_str.as_str());
if maybe_num.is_ok() {
return maybe_num.unwrap();
}
0 as T
}
fn main() {
let num_str = String::from("12");
println!("Converted to i32: {}", get_num_from_str::<i32>(&num_str));
}
Run Code Online (Sandbox Code Playgroud)
我发现Rust有一个Primitive
特征,之前被删除了.现在还有别的东西可以用吗?
我找到了一个解决方法:
use std::str::FromStr;
fn get_num_from_str<T: Default + FromStr>(maybe_num_str: &String) -> T {
let maybe_num = T::from_str(maybe_num_str.as_str());
maybe_num.unwrap_or(Default::default())
}
Run Code Online (Sandbox Code Playgroud)
正如特征约束所暗示的那样,这应该适用于任何具有两者的实现的东西Default
,FromStr
并且我应该重命名该函数以反映这一点,但是知道是否只有原始数字类型的任何特征我仍然会很好用于确保此功能不能用于数字类型以外的任何其他功能.
我是新手Python/Django程序员.
我创建了一个基于Django 2.0的应用程序,并根据官方文档打包它.然后我运行命令:
$ pip install --user django-easybuggy-0.1.tar.gz
Run Code Online (Sandbox Code Playgroud)
但是,我收到错误,无法安装.
Processing ./django-easybuggy-0.1.tar.gz
Collecting certifi==2018.1.18 (from django-easybuggy==0.1)
Could not find a version that satisfies the requirement certifi==2018.1.18 (from django-easybuggy==0.1) (from versions: )
No matching distribution found for certifi==2018.1.18 (from django-easybuggy==0.1)
Run Code Online (Sandbox Code Playgroud)
有谁知道错误发生的原因以及如何解决?
另外,我requirements.txt
通过命令创建:
$ pip freeze > requirements.txt
Run Code Online (Sandbox Code Playgroud)
重现步骤:
下载我的应用档案:
$ wget https://github.com/k-tamura/easybuggy4django/releases/download/0.0.1/django-easybuggy-0.1.tar.gz
Run Code Online (Sandbox Code Playgroud)运行命令:
$ pip install --user django-easybuggy-0.1.tar.gz
Run Code Online (Sandbox Code Playgroud)最好的祝福,
我使用IdentityServer4(v2.2.1)与.Net Core 2.0和Asp.Net核心身份.我的解决方案中有三个项目.
我正在尝试在我的Web API上实现基于角色的授权,以便任何客户端都可以将访问令牌传递给Web API以访问资源.
目前我可以在MVC应用程序控制器上实现Roles基础授权,但我无法为WEB API Controller传递/配置相同的权限.
以下是Identity Server Files:Config.cs
public static IEnumerable<ApiResource> GetApiResources()
{
return new List<ApiResource>
{
//SCOPE - Resource to be protected by IDS
new ApiResource("TCSAPI", "TCS API")
{
UserClaims = { "role" }
}
};
}
public static IEnumerable<Client> GetClients()
{
return new List<Client>
{
new Client
{
ClientId = "TCSIdentity",
ClientName = "TCS Mvc Client Application .",
AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,
RequireConsent = false,
ClientSecrets =
{
new Secret("secret".Sha256()) …
Run Code Online (Sandbox Code Playgroud) android ×2
java ×2
python ×2
architecture ×1
bash ×1
clojure ×1
django ×1
grid-search ×1
javascript ×1
json ×1
pip ×1
pipeline ×1
python-3.x ×1
rust ×1
scikit-learn ×1
sed ×1
setuptools ×1
spring-cloud ×1
tslint ×1
typescript ×1
webstorm ×1