2016-12-29 41 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