小编roh*_*wal的帖子

Spring电子邮件添加附件

我正在使用Spring 3.2并希望发送附件的电子邮件.我有一个字节数组 - 如何将其设置为附件?我这样做:

bytes[] doc = docDao.findNextDoc().getBytes();
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
try {
    MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
    helper.addAttachment("doc", ???); // how can I set bytes here?
}
.... 
// other things
Run Code Online (Sandbox Code Playgroud)

java email spring file

2
推荐指数
1
解决办法
2214
查看次数

如果启用延迟加载,rails 控制台如何提供查询结果集?

我有一个数据库表users。我正在尝试查询数据库以获取所有年龄大于 18 的用户。

adult_users = User.where('age > 18')
Run Code Online (Sandbox Code Playgroud)

根据延迟加载功能,不会执行上述查询,而只会创建一个 Active Record Relation。实际的查询只有在您调用adult_users.first或使用它进行其他一些操作时才会执行。
但是在 rails 控制台中,即使您点击User.where('age > 18'),您也可以看到查询正在执行。
这怎么会发生?

ruby lazy-loading ruby-on-rails

2
推荐指数
1
解决办法
719
查看次数

使用Spring @Lazy和@PostConstruct注释

我有以下课程:

@Repository
class A {

    public void method1() {
        ...
    }
}

@Component
class B implements C {

    @Autowired
    @Lazy
    private A a;

    public void method2() {
        a.method1();
    }
}

@Component
class D {

    @Autowired
    private List<C> c;

    @PostConstruct
    public void method3() {
        // iterate on list c and call method2()
    }
}
Run Code Online (Sandbox Code Playgroud)

让我们假设Spring将bean初始化如下:
1.创建第一个bean B. 当创建bean B时,a由于@Lazy注释,将不会初始化字段.
2.创建下一个bean D. 然后method3()将被标记为执行@PostConstruct,但Spring尚未触及bean A. 因此,当调用a.method1()时,Spring会创建bean A并将其注入字段中a还是会抛出NullPointerException

java spring annotations lazy-evaluation postconstruct

2
推荐指数
1
解决办法
4148
查看次数

WrappedArray的WrappedArray到java数组

我有一个类型集的列,我使用collect_set()spark数据集API,它返回一个包装数组的包装数组.我想要嵌套包装数组的所有值中的单个数组.我怎样才能做到这一点?

例如.卡桑德拉表:

Col1  
{1,2,3}
{1,5}
Run Code Online (Sandbox Code Playgroud)

我正在使用Spark Dataset API.
row.get(0)返回一个包装数组的包装数组.

java cassandra apache-spark apache-spark-dataset

2
推荐指数
1
解决办法
5152
查看次数

从转储文件创建的数据库的 Postgres 权限

我想创建一个数据库ABC。我想使用转储文件(例如 ABC_DUMP)将数据加载到 ABC 中。我希望用户 ABC_USER 拥有数据库 ABC 的所有访问权限,包括创建、选择、更改、更新。我使用以下命令登录 psql:

postgres@ubuntu:~$ psql
postgres=# CREATE DATABASE ABC;
postgres=# GRANT ALL PRIVELEGES ON DATABASE ABC TO ABC_USER;
postgres=# \q
postgres@ubuntu:~$ psql -h localhost ABC -U ABC_USER < ABC_DUMP
Password for user ABC_USER xxxxxx
CREATE FUNCTION
ERROR:  must be member of role "postgres"
CREATE FUNCTION
ERROR:  must be member of role "postgres"
CREATE FUNCTION
ERROR:  must be member of role "postgres"
CREATE FUNCTION
ERROR:  must be member of role "postgres"
CREATE AGGREGATE
ERROR:  must …
Run Code Online (Sandbox Code Playgroud)

postgresql

1
推荐指数
1
解决办法
2118
查看次数