我有一個項目工作,然後突然停下來。春天是失敗注入彈簧面不工作,intellij
@Configuration
@Order(2)
public static class RegularSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Inject
private Environment env;
@Inject
private AjaxAuthenticationSuccessHandler ajaxAuthenticationSuccessHandler;
//Could not autowire. No bean of name 'ajaxAuth..' type found
...
的AjaxAuthenticationSuccessHandler
類看起來像這樣
@Component
public class AjaxAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler {
@Autowired
private UserRepository userRepository;
...
我發現小了配置,但所在行與main
方法的文件以及@ComponentScan
是紅色的。
這是有關我的問題?如何告知Spring的ajaxAuth..
課程?即使我切換到以前工作的分支,也會發生這種情況。
這裏是Application.java
:
@ComponentScan
@EnableAutoConfiguration(exclude = {MetricFilterAutoConfiguration.class, MetricRepositoryAutoConfiguration.class})
public class Application {
private static final Logger log = LoggerFactory.getLogger(Application.class);
@Inject
private Environment env;
@PostConstruct
public void initApplication() {
if (env.getActiveProfiles().length == 0) {
log.warn("No Spring profile configured, running with default configuration");
} else {
log.info("Running with Spring profile(s) : {}", Arrays.toString(env.getActiveProfiles()));
}
}
/**
* Main method, used to run the application.
*/
public static void main(String[] args) throws UnknownHostException, NoSuchAlgorithmException {
if (Cipher.getMaxAllowedKeyLength("AES") <= 128) {
log.error("You need Java Cryptography Extension (JCE) to run the system");
return;
}
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
System.setProperty("user.timezone", "UTC");
SpringApplication app = new SpringApplication(Application.class);
app.setShowBanner(false);
SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);
// Check if the selected profile has been set as argument.
// if not the development profile will be added
addDefaultProfile(app, source);
addLiquibaseScanPackages();
Environment env = app.run(args).getEnvironment();
// System.setProperty("javax.net.ssl.trustStore", env.getProperty("server.ssl.key-store"));
// System.setProperty("javax.net.ssl.trustStorePassword", env.getProperty("server.ssl.key-store-password"));
String httpPort = env.getProperty("httpPort");
String httpsPort = env.getProperty("server.port");
String div = "----------------------------------------------------------";
String local = "\tLocal: \t\thttps://127.0.0.1:" + httpsPort;
String external = "\tExternal: \thttps://" + InetAddress.getLocalHost().getHostAddress() + ":" + httpsPort;
if (httpPort != null) {
div += "-----------------------------";
local += " & http://127.0.0.1:" + httpPort;
external += " & http://" + InetAddress.getLocalHost().getHostAddress() + ":" + httpPort;
}
log.info("Access URLs:\n" + div + "\n" + local + "\n" + external + "\n" + div);
}
/**
* Set a default profile if it has not been set
*/
private static void addDefaultProfile(SpringApplication app, SimpleCommandLinePropertySource source) {
if (!source.containsProperty("spring.profiles.active")) {
app.setAdditionalProfiles(Constants.SPRING_PROFILE_DEVELOPMENT);
}
}
/**
* Set the liquibases.scan.packages to avoid an exception from ServiceLocator.
*/
private static void addLiquibaseScanPackages() {
System.setProperty("liquibase.scan.packages", Joiner.on(",").join(
"liquibase.change", "liquibase.database", "liquibase.parser",
"liquibase.precondition", "liquibase.datatype",
"liquibase.serializer", "liquibase.sqlgenerator", "liquibase.executor",
"liquibase.snapshot", "liquibase.logging", "liquibase.diff",
"liquibase.structure", "liquibase.structurecompare", "liquibase.lockservice",
"liquibase.ext", "liquibase.changelog"));
}
}
我試過這個。我最終在我之前的同一個地方:/ – OrangePot
應用程序類是否公開?你有沒有解決的類路徑條目?您是否嘗試通過Maven/Gradle重新導入?最終損壞了JAR的緩存? –
林不知道你通過Maven重新進口意味着什麼。 Intellij允許您通過行號在「@ ComponentScan」旁邊單擊「bean」,我猜這是它處理的所有bean。在類中有'ajaxAuth..java',所以它知道它。我不知道爲什麼它沒有被注入,如果它知道它。 – OrangePot