2017-02-27 127 views
0

我有一个项目工作,然后突然停下来。春天是失败注入弹簧面不工作,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是红色的。

enter image description here

这是有关我的问题?如何告知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")); 
    } 

} 

回答

0

似乎有解决您的主类Application.java问题。只需尝试删除并重新添加Spring方面(您需要另外重新创建手动上下文)。

+0

我试过这个。我最终在我之前的同一个地方:/ – OrangePot

+0

应用程序类是否公开?你有没有解决的类路径条目?您是否尝试通过Maven/Gradle重新导入?最终损坏了JAR的缓存? –

+0

林不知道你通过Maven重新进口意味着什么。 Intellij允许您通过行号在“@ ComponentScan”旁边单击“bean”,我猜这是它处理的所有bean。在类中有'ajaxAuth..java',所以它知道它。我不知道为什么它没有被注入,如果它知道它。 – OrangePot

0

我有一个JHipster生成春季启动应用程序类相同的问题,直到我添加了一个@Configuration注释到类:

@Configuration 
@ComponentScan 
@EnableAutoConfiguration(exclude = {MetricFilterAutoConfiguration.class, 
MetricRepositoryAutoConfiguration.class}) 
public class Application { 
    /* ... */ 
} 

的三个注释或者可以用一个@SpringBootApplication注释改为:

@SpringBootApplication(exclude = {MetricFilterAutoConfiguration.class, 
MetricRepositoryAutoConfiguration.class}) 
public class Application { 
    /* ... */ 
} 

两者似乎都与IDEA 2017.1一起使用。