0
I’m trying to use the swing and the spring but I have this problem:
Exception in thread "restartedMain" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.market.controller.LoginController' available
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:346)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:337)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1123)
at com.market.app.MarketApplication.main(MarketApplication.java:17)
... 5 more
my main:
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import com.market.controller.LoginController;
@SpringBootApplication
@EnableAutoConfiguration
public class MarketApplication {
public static void main(String[] args) {
ConfigurableApplicationContext context = new SpringApplicationBuilder(MarketApplication.class).headless(false).run(args);
LoginController appLogin = context.getBean(LoginController.class);
}
}
my controller:
package com.market.controller;
import java.util.List;
import javax.swing.JOptionPane;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import com.market.action.AbstractAction;
import com.market.model.Funcionarios;
import com.market.ui.LoginFrame;
@Controller
public class LoginController extends AbstractController {
@Autowired
private LoginFrame frame;
private void init() {
this.frame.addWindowListener(this);
registerAction(frame.getbEnter(), new AbstractAction() {
private List<Funcionarios> list;
@Override
public void action() {
if (!frame.getjLogin().getText().trim().isEmpty() || !frame.getjPassword().getText().trim().isEmpty()) {
}else {
JOptionPane.showMessageDialog(frame, null, "Campo vázio", JOptionPane.INFORMATION_MESSAGE);
}
}
@Override
public void posAction() {
cleanUp();
}
});
}
public void show() {
frame.setVisible(true);
}
@Override
protected void cleanUp() {
frame.setVisible(false);
frame.resetForm();
super.cleanUp();
}
}
my view:
package com.market.ui;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.jnativehook.keyboard.NativeKeyEvent;
import org.springframework.stereotype.Component;
@Component
public class LoginFrame extends JFrame {
private static final int FRAME_WIDTH = 400;
static final int FRAME_HEIGHT = 350;
static final int FRAME_X_ORIGIN = 150;
static final int FRAME_Y_ORIGIN = 150;
static final int BUTTON_WIDTH = 90;
static final int BUTTON_HEIGHT = 30;
private JTextField jLogin;
private JTextField jPassword;
private JButton bEnter;
private JButton bRegister;
private JPanel loginForm;
private JLabel loginText;
private JLabel passwordText;
public LoginFrame() {
setTitle("Login System");
setSize (FRAME_WIDTH, FRAME_HEIGHT);
setLocation (FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());
setResizable(false);
initComponents();
}
private void initComponents() {
loginForm = new JPanel(new GridLayout(3,1));
//buttons
bRegister = new JButton("Registrar");
bRegister.setBounds(195, 285, BUTTON_WIDTH, BUTTON_HEIGHT);
bEnter = new JButton("Registrar");
bEnter.setBounds(195, 285, BUTTON_WIDTH, BUTTON_HEIGHT);
bEnter.setMnemonic(NativeKeyEvent.VC_ENTER);
//labels
loginText = new JLabel();
loginText.setText("Username:");
passwordText = new JLabel();
passwordText.setText("Password:");
//
loginForm.add(loginText);
loginForm.add(jLogin);
loginForm.add(passwordText);
loginForm.add(jPassword);
loginForm.add(bEnter);
loginForm.add(bRegister);
setVisible(true);
}
public void resetForm() {
jLogin.setText("");
jPassword.setText("");
}
public JTextField getjLogin() {
return jLogin;
}
public void setjLogin(JTextField jLogin) {
this.jLogin = jLogin;
}
public JTextField getjPassword() {
return jPassword;
}
public void setjPassword(JTextField jPassword) {
this.jPassword = jPassword;
}
public JButton getbEnter() {
return bEnter;
}
public void setbEnter(JButton bEnter) {
this.bEnter = bEnter;
}
}
thanks a lot bro I had remade and worked, but I had no idea the reason, now it worked exactly on account of my main is in the first package.
– Joao Spirit