小编Pro*_*Rev的帖子

如何从不在Spring容器中的类访问Spring Bean的方法

我不是春天职业选手,所以请耐心等待....

我有三个班:

class SpringBeanA {
    public aMethod() {
        .....
    }
}

class SpringBeanB {

    @Autowired SpringBeanA a;

    public bMethod() {
        a.method();
    }
}

class NONSpringClass {
    .....
    b.method();
    .....
}
Run Code Online (Sandbox Code Playgroud)

b.method()在通过实例进行接口SpringBeanB b = new SpringBeanB()并将SpringBeanB自动装配到NONSpringClass 时,会发出空指针错误.

自动装配:

class NONSpringClass {

    @Autowired SpringBeanB b;

    .....
    b.method();
    .....
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能成功打电话b.method()

java spring spring-mvc

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

创建程序集归档文件箱时出错:您必须至少设置一个文件

我有一个模块调用一个Maven多模块项目MOD1,我试图添加到一个文件夹/project jarsmvn assembly:assembly从应用程序文件夹,其中的应用程序pom.xml的是.

错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.3:single (assembly) on project wrapper: Failed to create assembly
: Error creating assembly archive bin: You must set at least one file. -> [Help 1]
Run Code Online (Sandbox Code Playgroud)

项目文件夹结构:

app
    | pom.xml
    | src    | main     | ...
wrapper
    | pom.xml
    | src    | main     | ...
mod1
    | pom.xml
    | src    | main     | ...

// After mvn assembly:assembly

project jars
    | mod1.jar
Run Code Online (Sandbox Code Playgroud)

mod1 pom.xml

<project>
  <groupId>org.test</groupId> …
Run Code Online (Sandbox Code Playgroud)

java maven maven-assembly-plugin

7
推荐指数
1
解决办法
4万
查看次数

如何在Qt中使用FontAwesome

FontAwesome使得将可编辑的图标添加到HTML中非常简单:

<link rel="stylesheet" href="path/to/font-awesome/css/font-awesome.min.css">

<i class="fa fa-camera-retro"></i>
Run Code Online (Sandbox Code Playgroud)

我尝试将FontAwesome图标添加到Qt小部件,但它没有显示:

QPushButton *qB = new QPushButton("TXT");
qB -> setProperty("class", "fa fa-camera-retro");
Run Code Online (Sandbox Code Playgroud)

我怎样才能使它与Qt小部件一起使用?

c++ qt font-awesome

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

使用JmDNS的样本

我已经能够获得JmDNS附带的样本进行编译和运行,但是我无法获得任何类来发现我的服务.

我正在运行一个Windows环境,其中有多个PC正在运行VNC,SSH和Apache,我一直试图让JmDNS发现其中至少有一个......

我理想的是能够检测到我网络上所有正在运行的VNC服务器.是否存在某种客户端和服务器配对,如果我使用JmDNS注册它,我只能发现服务?

任何帮助从样本中获得一些结果将不胜感激,文档没有太大的帮助.

import java.io.IOException;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.jmdns.JmDNS;
import javax.jmdns.ServiceEvent;
import javax.jmdns.ServiceListener;

/**
 * Sample Code for Service Discovery using JmDNS and a ServiceListener.
 * <p>
 * Run the main method of this class. It listens for HTTP services and lists all changes on System.out.
 *
 * @author Werner Randelshofer
 */
public class DiscoverServices {

    static class SampleListener implements ServiceListener {
        @Override
        public void serviceAdded(ServiceEvent event) {
            System.out.println("Service added   : " + event.getName() + …
Run Code Online (Sandbox Code Playgroud)

java jmdns

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

如何在单击任务栏图标时最小化未修饰的阶段

我有一个未修饰的舞台.我希望它在Windows 7任务栏上的图标被点击时最小化.我怎样才能做到这一点?

public void popStage(Parent view, Dimension d) {
    Scene scene = new Scene(view);

    stage.initStyle(StageStyle.UNDECORATED);
    stage.initStyle(StageStyle.TRANSPARENT);
    stage.initModality(Modality.WINDOW_MODAL);

    StageDraggable.stageDraggable(view, stage);
    stage.getIcons().add(new Image(Resources.getBrickbreaker()));
    stage.setScene(scene);

    stage.setWidth(d.getWidth());
    stage.setHeight(d.getHeight());
    stage.show();
}
Run Code Online (Sandbox Code Playgroud)

java javafx

6
推荐指数
0
解决办法
1054
查看次数

如何使用ThymeLeaf发送带有内嵌图像的电子邮件

我正在尝试使用ThymeLeaf和Spring发送带有内嵌图像的电子邮件,但到目前为止还没有成功.电子邮件发送,但内嵌图像不会显示在电子邮件中.

该项目不是基于网络的(不是网站),而是一个独立的桌面,而不是移动

这是我获取图像文件的方式:

URL url = getClass().getResource("/LawFirmAdvisoryGroup.jpg");
File file = new File(url.getPath());

MultipartFile multipartFile = new MockMultipartFile(file.getName(),
    file.getName(), "image/jpeg", IOUtils.toByteArray(input));
Run Code Online (Sandbox Code Playgroud)

我的服务类:

@Autowired
private JavaMailSender mailSender;

@Autowired
private TemplateEngine templateEngine;

public void sendMailWithInline(final String recipientName, final String recipientEmail, final MultipartFile image, final byte[] imageBytes)
throws MessagingException {

    final Context ctx = new Context();
        ctx.setVariable("imageResourceName", image.getName()); // so that we can reference it from HTML

        final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
        final MimeMessageHelper message
        = new MimeMessageHelper(mimeMessage, true, "UTF-8");
        message.setSubject("Inline Image");
        message.setFrom("XXXX@yahoo.com");
        message.setTo(recipientEmail); …
Run Code Online (Sandbox Code Playgroud)

java thymeleaf

6
推荐指数
2
解决办法
6889
查看次数

如何在HBox左,中,右对齐儿童

我有一个孩子的HBox设置如下:

HBox h = new HBox();
h.setMinWidth(555);

Label leftLabel = new Label("Left");
Label centerLabel = new Label("Center");

HBox rightContent = new HBox();
Label r1 = new Label("2");
Label r2 = new Label("3");

rightContent.getChildren().addAll(r1, r2);
h.getChildren().addAll(leftLabel, centerLabel, rightContent);
Run Code Online (Sandbox Code Playgroud)

这将创建一个HBox,左边是所有孩子.我想leftLabel是在左边,centerLabel在该中心,并rightContent最右端.

我怎样才能做到这一点?

谢谢大家.

java javafx

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

如何遍历QStringList

我正在尝试遍历两个不同的目录.这两个目录位于同一个根目录下/.

void MainWindow::loadPlugins()
{
    pluginsDir = QDir(qApp -> applicationDirPath());

#if defined(Q_OS_WIN)
    if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
        pluginsDir.cdUp();
#elif defined(Q_OS_MAC)
    if (pluginsDir.dirName() == "MacOS") {
        pluginsDir.cdUp();
        pluginsDir.cdUp();
        pluginsDir.cdUp();
    }
#endif

    QStringList dirs;
    dirs << "plugins" << "core_plugs";

    QList<QObject *> loadedPlugs;

    for (int i = 0; i < dirs.size(); ++i)
    {
        cout << dirs.at(i).toLocal8Bit().constData() << endl;

        pluginsDir.cd(dirs.at(i).toLocal8Bit().constData());

        foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
            QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
            QObject *plugin = loader.instance();
            qDebug() << "NAME :: " << fileName;
            if (plugin …
Run Code Online (Sandbox Code Playgroud)

c++ iteration qstring qt qlist

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

简单的Java"服务提供者框架"?

我指的是有效Java第2章中讨论的"服务提供者框架" ,这似乎是处理我遇到的问题的正确方法,我需要在运行时实例化几个类中的一个,基于a String选择哪个服务和Configuration对象(本质上是一个XML片段):

但是,我如何让各个服务提供商(例如一堆默认提供商+一些自定义提供商)进行自我注册?

 interface FooAlgorithm
 {
     /* methods particular to this class of algorithms */
 }

 interface FooAlgorithmProvider
 {
     public FooAlgorithm getAlgorithm(Configuration c);
 }

 class FooAlgorithmRegistry
 {
     private FooAlgorithmRegistry() {}
     static private final Map<String, FooAlgorithmProvider> directory =
        new HashMap<String, FooAlgorithmProvider>();
     static public FooAlgorithmProvider getProvider(String name)
     {
         return directory.get(serviceName);
     }
     static public boolean registerProvider(String name, 
         FooAlgorithmProvider provider)
     {
         if (directory.containsKey(name))
            return false;
         directory.put(name, provider);
         return true;
     }
 }
Run Code Online (Sandbox Code Playgroud)

例如,如果我编写自定义类MyFooAlgorithm和MyFooAlgorithmProvider来实现FooAlgorithm,并将它分发到jar中,是否有任何方法可以自动调用registerProvider,或者我使用该算法的客户端程序是否必须显式调用FooAlgorithmRegistry.registerProvider( )他们想要使用的每个班级?

java factory service-provider

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

如何通过注解在Spring bean Autowired中传递类构造函数参数

没有 IOC 容器的正常方法是:

new User("Names", 22);
Run Code Online (Sandbox Code Playgroud)

这里的参数值是动态的,例如,它们是通过用户提交表单获取的,因此不能存储在文件中。

TextField userNames = new TextField();

names = userNames.getText()
Run Code Online (Sandbox Code Playgroud)

其他参数相同。

在哪里:

@Component
public class User {
    public User(String names, int age) {
        .
        .
        .
    }
}
Run Code Online (Sandbox Code Playgroud)

我如何初始化User,同时传递构造函数的参数,其中 UserAutowired进入另一个类:

@Component
public class AnotherClass {
    @Autowired
    User user(....)????? // How do I do it here
    .
    .
    .
}
Run Code Online (Sandbox Code Playgroud)

java spring

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