ComponentScan和import org.springframework.context.annotation.ComponentScan无法解析为类型

时间:2017-11-18 09:09:46

标签: spring hibernate maven

我的Spring项目有问题。首先,我无法在服务器上运行它,但在再次下载所有资源后,它就开始了。

但是现在我有一些Spring无法看到的进口 例如:

import org.springframework.context.annotation.ComponentScan can not be resolved as a type.

和自动接线值

@ComponentScan  can not be resolved as a type.

因为hibernate没有在我的数据库中创建表(我想是这样)

另外两个配置类有一些错误:

Spring4Initializer类型的层次结构不一致 SpringSecurityInitializer

public class Spring4Initializer extends AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[] { Spring4Configuration.class };
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return null;
    }

    @Override
    protected String[] getServletMappings() {
        return new String[] { "/" };
    }

    @Override
    protected Filter[] getServletFilters() {
        CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
        characterEncodingFilter.setEncoding("UTF-8");
        characterEncodingFilter.setForceEncoding(true);
        return new Filter[] { characterEncodingFilter };
    }
}

SpringSecurityInitializer此行的多个标记      - 无法解析org.springframework.web.WebApplicationInitializer类型。它是间接引用的      必需的.class文件

import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;

public class SpringSecurityInitializer extends AbstractSecurityWebApplicationInitializer {

}

我已经尝试了maven clean和maven build

[WARNING] 
[WARNING] Some problems were encountered while building the effective model for pl.dmcs:eschool:war:1.0.0-BUILD-SNAPSHOT
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework:spring-context:jar -> version ${org.springframework-version} vs 4.3.7.RELEASE @ line 74, column 17
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: com.fasterxml.jackson.core:jackson-databind:jar -> version 2.8.8 vs 2.8.3 @ line 157, column 15
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: javax.servlet:servlet-api:jar -> version ${servlet-api-version} vs 2.5 @ line 254, column 15
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework:spring-context:jar -> version ${org.springframework-version} vs 3.0.5.RELEASE @ line 271, column 14
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building E-School 1.0.0-BUILD-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ eschool ---
[INFO] Deleting C:\Users\Piotr\Desktop\E-School\target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

有谁知道我应该怎么做才能让hibernate工作? 在Outline树中,我的函数GetHibernateProperites()被标记为红色

1 个答案:

答案 0 :(得分:0)

你是否在你的maven依赖项中包含了spring-context?我想你错过了那种依赖。