我有2个默认方法的接口。如果找不到实现,则希望使用这2个默认方法自动装配代理bean。春天有可能吗?
我编写了以下bean来验证我的邮件.
public class Mail_Authenticator {
public Session Get_Auth() {
// sets SMTP server properties
ResourceBundle rs_mail = ResourceBundle.getBundle("mail");
final String userName=rs_mail.getString("username");
final String password=rs_mail.getString("password");
Properties properties = new Properties();
properties.put("mail.smtp.host", "smtp.gmail.com");
properties.put("mail.smtp.port", "587");
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.starttls.enable", "true");
properties.put("mail.user", userName);
//creates a new session with an authenticator
Authenticator auth = new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(userName, password);
}
};
return (Session.getInstance(properties, auth));
}
}
Run Code Online (Sandbox Code Playgroud)
问题在于smtp设置,当我在本地服务器上运行应用程序时,它工作正常.但是当我在openshift服务器上运行应用程序时会导致异常
Transport.send(msg);
Run Code Online (Sandbox Code Playgroud)
任何人都可以指出问题,在上面的设置中,为什么他们在我的本地机器上工作?
以下是我得到的例外
javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbsWq 534-5.7.14 JJjb_c-FzrtUAccdDqOCMtsPAOL1AwIDSCoireBRoI5X-avznrYbparV84O_zkAvrHXMB9 534-5.7.14 T0Zj8zXP1g1woaWHnTzJQ3vWFn3lwTNl9Kn8Ma9-d9FPD_xB-bMBSh5FEPdaMqID4WljXW 534-5.7.14 …Run Code Online (Sandbox Code Playgroud) 我正在尝试索引从 tomcat 服务器获取的大量日志文件。我编写了代码来打开每个文件,为每行创建索引,然后使用 Apache lucene 存储每行。所有这些都是使用多线程完成的。
当我尝试这段代码时,我得到了这个异常
org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out:
Run Code Online (Sandbox Code Playgroud)
代码
if (indexWriter.getConfig().getOpenMode() == IndexWriterConfig.OpenMode.CREATE)
{
// New index, so we just add the document (no old document can be there):
System.out.println("adding " + path);
indexWriter.addDocument(doc);
} else {
// Existing index (an old copy of this document may have been indexed) so
// we use updateDocument instead to replace the old one matching the exact
// path, if present:
System.out.println("updating " + path);
indexWriter.updateDocument(new Term("path", path), doc); …Run Code Online (Sandbox Code Playgroud) Cookie只是一小段信息,大多数情况下客户端向服务器发送请求标头中的字符串.如果我在java中的服务器上添加一个字符串到请求头, conn.addRequestProperty("iPlanetDirectoryPro", token);那么两者之间有什么区别吗?第二个也可以被视为cookie.
问候,
麦克莱恩莫里斯平托
当我做git checkout origin/bugfix/NTP-183-datefnsgit 显示时
Note: checking out 'origin/bugfix/NTP-183-datefns'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is …Run Code Online (Sandbox Code Playgroud) 以下是我从外部服务获得的json响应.
{"userAttributeList": [
{"Name":"PROFILE.UUID","Value":”SL1-4XXXXX0"},
{"Name":"PROFILE.UserId","Value":"John.Smith@bigBank.com"},
{"Name":"PROFILE.FirstName","Value":"John"},
{"Name":"PROFILE.LastName","Value":"Smith"},
{"Name":"PROFILE.EmailAddress","Value":"John.Smith@bigBank.com"},
{"Name":"SETTING.COMMON.REGIONAL_SETTINGS.DATEFORMAT_DATEPATTERN","Value":"dddd d MMMM yyyy"},
{"Name":"SETTING.COMMON.REGIONAL_SETTINGS.DATEFORMAT_TIMEPATTERN","Value":"HH:mm:ss"},
{"Name":"SETTING.COMMON.REGIONAL_SETTINGS.DATEFORMAT_TIMEZONE","Value":"Romance Standard Time"}
]}
Run Code Online (Sandbox Code Playgroud)
我仍然试图将这个数字反序化.它不是形式.任何人都可以建议一种方法来解决这个问题.
当我使用字符串作为方法的参数时,函数中字符串的更改不会反映在调用函数中.简单的理由按价值传递.
但是当使用向量时,对向量的更改将反映在调用函数中.所以我的问题是传递向量就像调用引用一样,我们在内存中发送地址而不是变量,因此函数内的任何更改都会反映在调用函数中
------------------------更新------------------------- -------
所以向量必须仅通过引用传递?我不能正常做到吗?
当然你可以正常传递它们(通过值传递它们).但是当你按值传递对象时,会发生一个新对象,然后将传递的对象复制到新对象.此,对于标准类型(字符型,整型,浮点等等)是确定的,因为标准类型的体积小(char是一个字节,短为2,int是2或4,长为4等...).然而,矢量并不小.试着这样做:
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> v;
cout << sizeof(v) << endl;
system("pause");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在我的电脑中我得到12作为输出.这是12个字节.因此,我不是通过值传递,而是通过引用传递它,其成本为4个字节(包含我的向量地址的变量的大小)
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package corejava;
/**
*
* @author Administrator
*/
public class CoreJava {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Test test=new Test();
test.setx(20);
test.printx();
Test test1=test;
test1.setx(40);
test1.printx();
test.printx();
int a=20;
int b=a;
a=40;
System.out.println(a);
System.out.println(b);
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
run:
X is 20
X is 40
X is 40
40
20
Run Code Online (Sandbox Code Playgroud)
现在,当我在“a”中设置“x”的值并将对象“a”分配给“b”时,“b”将指向对象“a”的相同值。因此对“a”的任何更改也会更改“b”的值;
但是当我使用简单变量时,为什么它不像对象那样做。为什么对象存储在堆中,变量存储在栈区。