2017-07-27 145 views
0

我以开头SpringBoot,看起来不错,但我有一些问题我无法理解或在文档中找到解释。Spring Boot不识别Spring MVC

我使用Web,JPA,安全MySQL依赖关系创建了一个新项目。当我的项目创建时,我将创建一个@Controller类。 Spring没有找到@RequestMappingModelAndView类。

我猜使用SpringBoot的Web模块将添加所有必要的依赖使用用SpringMVC(我看了一些例子,没有添加额外的依赖)和所有MVC工作的伟大。

这是我的依赖关系:

<dependencies> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-data-jpa</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-groovy-templates</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-security</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 

     <dependency> 
      <groupId>mysql</groupId> 
      <artifactId>mysql-connector-java</artifactId> 
      <scope>runtime</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-tomcat</artifactId> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-test</artifactId> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-test</artifactId> 
      <scope>test</scope> 
     </dependency> 
     <!-- Utils --> 
     <dependency> 
      <groupId>com.google.guava</groupId> 
      <artifactId>guava</artifactId> 
      <version>22.0</version> 
     </dependency> 
    </dependencies> 

其他例子,是WebMvcConfigurerAdapter(从弹簧MCV)类,我解决不了: org.springframework.web.servlet.config.annotation .WebMvcConfigurerAdapter;

这个类是从,但我没有看到Springboot包括此dependy: org.springframework 弹簧webmvc

也许我错了,看了一些帖子说中心的所有信息在春季启动,但不要在poms中显示手动配置。

WebApplication的类(自动生成):

@SpringBootApplication 
public class WebApplication { 

    public static void main(String[] args) { 
     SpringApplication.run(WebApplication.class, args); 
    } 
} 

ServletInitializer.java类(自动生成)

public class ServletInitializer extends SpringBootServletInitializer { 

    @Override 
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 
     return application.sources(WebApplication.class); 
    } 

} 
+0

你宣布了一个spring引导应用程序类吗? – davidxxx

+0

此时我使用默认类(原始文章更新)。 – Genaut

+0

依赖关系看起来不错。你已经完成了一个mvn干净安装? –

回答

0

看起来像我的Maven的本地仓库已损坏。 enter image description here

我在其他项目中使用这些库,所有工作正常。对不起,浪费时间。无论如何,我让一些用户遇到类似问题的答复。

相关问题