2016-12-29 52 views
-7

我已经创建了一个简单的helloWorld maven依赖项,并将其放置在我的springmvc项目pom.xml中,但是在部署其合格bean的helloWorld: not的显示bean创建例外时。Maven依赖关系不能与springMVC项目合作

任何帮助,将不胜感激。谢谢。 我依赖项目在这里的样子 我Application.java com.test包

@Configuration 
@EnableAutoConfiguration 
@ComponentScan({"com.test"}) 
@EnableTransactionManagement 
public class Application { 
     public static void main(String[] args) { 
      System.out.println("hai"); 
      SpringApplication app = new SpringApplication(Application.class); 
      app.run(args); 
     } 
} 
My Controller 

    package com.test.controller; 

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.bind.annotation.RestController; 


import test.Application; 
import test.controller.Check; 

@RestController 
@RequestMapping("/Rest") 
public class Controller { 

    @Autowired 
    Check check; // this is the bean from that dependency 

    @RequestMapping(value="/logs",method=RequestMethod.GET) 
    public String logs(){ 

     return "I am the controler"; 
    } 
} 

我的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>waffleTalentpool</groupId> 
<artifactId>waffleTalentpool</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<packaging>war</packaging> 
<build> 
    <sourceDirectory>src</sourceDirectory> 
    <plugins> 
     <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>3.3</version> 
      <configuration> 
       <source>1.8</source> 
       <target>1.8</target> 
      </configuration> 
     </plugin> 
     <plugin> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>2.6</version> 
      <configuration> 
       <warSourceDirectory>WebContent</warSourceDirectory> 
       <failOnMissingWebXml>false</failOnMissingWebXml> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
     </plugin> 
    </plugins> 
</build> 
<properties> 
    <java.version>1.8</java.version> 
</properties> 
<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.3.1.RELEASE</version> 
</parent> 
<dependencies> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-mongodb</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>com.google.code.gson</groupId> 
     <artifactId>gson</artifactId> 
     <version>2.6.2</version> 
    </dependency> 
    <dependency> 
     <groupId>org.neo4j</groupId> 
     <artifactId>server-api</artifactId> 
     <version>2.3.2</version> 
    </dependency> 
    <dependency> 
     <groupId>com.github.dblock.waffle</groupId> 
     <artifactId>waffle-jna</artifactId> 
     <version>1.8.1</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.security</groupId> 
     <artifactId>spring-security-core</artifactId> 
     <version>3.2.0.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>com.github.dblock.waffle</groupId> 
     <artifactId>waffle-tomcat8</artifactId> 
     <version>1.7.3</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
     <exclusions> 
      <exclusion> 
       <artifactId>logback-classic</artifactId> 
       <groupId>ch.qos.logback</groupId> 
      </exclusion> 
      <exclusion> 
       <artifactId>log4j-over-slf4j</artifactId> 
       <groupId>org.slf4j</groupId> 
      </exclusion> 
     </exclusions> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-aop</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-test</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>log4j</groupId> 
     <artifactId>log4j</artifactId> 
     <version>1.2.17</version> 
    </dependency> 
    **<dependency> 
     <groupId>test</groupId> 
     <artifactId>test</artifactId> 
     <version>0.0.1-SNAPSHOT</version> 
    </dependency>** // This is my maven dependency for standalone java application 

    <dependency> 
     <groupId>joda-time</groupId> 
     <artifactId>joda-time</artifactId> 
     <version>2.3</version> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.poi</groupId> 
     <artifactId>poi</artifactId> 
     <version>3.10-FINAL</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.poi</groupId> 
     <artifactId>poi-ooxml</artifactId> 
     <version>3.10-FINAL</version> 
    </dependency> 
    <dependency> 
     <groupId>javax.mail</groupId> 
     <artifactId>mail</artifactId> 
     <version>1.4</version> 
    </dependency> 
    <dependency> 
     <groupId>javax.activation</groupId> 
     <artifactId>activation</artifactId> 
     <version>1.1.1</version> 
    </dependency> 
    <dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
     <version>5.1.6</version> 
    </dependency> 
    <dependency> 
     <groupId>commons-fileupload</groupId> 
     <artifactId>commons-fileupload</artifactId> 
     <version>1.2</version> 
    </dependency> 

    <dependency> 
     <groupId>commons-io</groupId> 
     <artifactId>commons-io</artifactId> 
     <version>1.3.1</version> 
    </dependency> 


</dependencies> 
<repositories> 
    <repository> 
     <id>spring-releases</id> 
     <name>Spring Releases</name> 
     <url>https://repo.spring.io/libs-release</url> 
    </repository> 
</repositories> 
<pluginRepositories> 
    <pluginRepository> 
     <id>spring-releases</id> 
     <name>Spring Releases</name> 
     <url>https://repo.spring.io/libs-release</url> 
    </pluginRepository> 
</pluginRepositories> 

我的web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> 
    <display-name>waffleTalentpool</display-name> 
    <welcome-file-list> 
    <welcome-file>index.html</welcome-file> 
    </welcome-file-list> 
    <servlet> 
    <servlet-name>TP</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 

    <init-param> 
     <param-name>contextClass</param-name> 
     <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value> 
    </init-param> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>com.test.Application</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
    <servlet-name>TP</servlet-name> 
    <url-pattern>/tp/*</url-pattern> 
    </servlet-mapping> 
</web-app> 

我的源代码链接 here

+0

提供更多的细节 - 日志,配置等 – bsiamionau

+0

最有可能的问题是不是在项目依赖,但在缺少豆 – bsiamionau

+0

谢谢您的答复。我在我的问题中也添加了我的代码 – Bishnu

回答

0

您的项目结构不遵循maven标准。我更新了结构并在此处上传。请尝试,让我知道是否可行

https://drive.google.com/file/d/0B3qylcHD3O-ddjVJLXRuOF9zM1U/view?usp=sharing

+0

上面的答案是关于spring引导应用程序的。你需要对你的Application.java进行一些小改动,以使战争应用程序能够正常工作。更改以将额外的软件包测试添加到@ComponentScan({“com.test”,“test”})批注 –

+0

没有无效。我得到同样的例外。 – Bishnu