首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >文件找不到Spring项目的问题

文件找不到Spring项目的问题
EN

Stack Overflow用户
提问于 2017-03-17 02:47:36
回答 2查看 1.1K关注 0票数 3

我试图让一个简单的Spring项目启动并运行,但它似乎不起作用。没有错误。试着改变不同的东西但没有运气。以下是课程

AppInitializer.java

代码语言:javascript
复制
package com.spring.config;

import java.util.Set;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

public class AppInitializer implements WebApplicationInitializer {  

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    // Create the 'root' Spring application context
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.scan("com.spring");

    // Manages the lifecycle of the root application context
    servletContext.addListener(new ContextLoaderListener(rootContext));

    // Declare dispatcher servlet. Handles requests into the application
    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher",
            new DispatcherServlet(rootContext));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");



}



}

WebAppContextConfig.java

代码语言:javascript
复制
   package com.spring.config;

    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
    import org.springframework.web.servlet.config.annotation.EnableWebMvc;
    import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
    import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.spring")
public class WebAppContextConfig extends WebMvcConfigurerAdapter {

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    @Bean
    public InternalResourceViewResolver configureInternalResourceViewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/views/");
        resolver.setSuffix(".jsp");
        return resolver;
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/scripts/**").addResourceLocations("/scripts/");
        registry.addResourceHandler("/css/**").addResourceLocations("/css/");
        registry.addResourceHandler("/img/**").addResourceLocations("/img/");
        registry.addResourceHandler("/fonts/**").addResourceLocations("/fonts/");
        registry.addResourceHandler("/vendor/**").addResourceLocations("/vendor/**");
    }

}

AppConfig.java`

代码语言:javascript
复制
package com.spring.config;

import org.springframework.context.annotation.Configuration;

@Configuration

public class AppConfig {

}

HelloController.java

代码语言:javascript
复制
package com.spring.controller;

   import org.springframework.stereotype.Controller;
   import org.springframework.web.bind.annotation.RequestMapping;
   import org.springframework.web.bind.annotation.RequestMethod;
   import org.springframework.web.bind.annotation.ResponseBody;

@Controller
  public class HelloController {

@RequestMapping(value = "/", method = RequestMethod.GET)
@ResponseBody
public String showIndex() {
    return "Hello world";
}

@RequestMapping(value = "/statuscheck", method = RequestMethod.GET)
public @ResponseBody
String getStatusCheck() {
    return "SUCCESS";
}



  }

pom.xml

我获得了spring上下文(4.3.0-RELEASE)、spring (4.3.0-RELEASE)、javax.servlet-api、jstl作为依赖项。

我正在使用websphere 8.5.5.9

我试过查这个网址:

代码语言:javascript
复制
http://localhost:8080/SpringProject/statuscheck

我得到了

代码语言:javascript
复制
[WARNING ] SRVE0190E: File not found: /statuscheck

编辑-1

我在server.xml里有这个

代码语言:javascript
复制
  <webApplication id="SpringProject" contextRoot = "SpringProject" location="SpringProject.war" name="SpringProject"/>

编辑-2

我在pom.xml .So中有这段代码,我没有web.xml

代码语言:javascript
复制
<plugin>
<groupId>org.apache.maven.plugins</groupId> 
<artifactId>maven-war-plugin</artifactId> 
<version>2.4</version> 
   <configuration>      
<warSourceDirectory>src/main/webapp</warSourceDirector‌​y>    
<warName>SpringProject</warName> 
<failOnMissingWebXml>false</failOnMissingWebXml> 
   </configuration> 
</plugin> 

编辑-3

这是日志文件。我看不出日志里有什么问题

代码语言:javascript
复制
[3/20/17 15:29:25:666 CDT] 00000001 id=         com.ibm.ws.kernel.launch.internal.FrameworkManager           I CWWKE0002I: The kernel started after 4.637 seconds
[3/20/17 15:29:32:064 CDT] 0000001d id=         com.ibm.ws.security.ready.internal.SecurityReadyServiceImpl  I CWWKS0007I: The security service is starting...
[3/20/17 15:29:32:089 CDT] 0000001d id=         ibm.ws.security.registry.basic.internal.DynamicBasicRegistry W CWWKS3103W: There are no users defined for the BasicRegistry configuration of ID basic.
[3/20/17 15:29:32:524 CDT] 0000001d id=         com.ibm.ws.security.jaspi.AuthConfigFactoryWrapper           I CWWKS1655I: The default Java Authentication SPI for Containers (JASPIC) AuthConfigFactory class com.ibm.ws.security.jaspi.ProviderRegistry is being used because the Java security property authconfigprovider.factory is not set. 
[3/20/17 15:29:32:555 CDT] 0000001d id=         com.ibm.ws.app.manager.internal.monitor.DropinMonitor        A CWWKZ0058I: Monitoring dropins for applications. 
[3/20/17 15:29:32:585 CDT] 0000003c id=         com.ibm.ws.security.ready.internal.SecurityReadyServiceImpl  I CWWKS0008I: The security service is ready.
[3/20/17 15:29:32:586 CDT] 0000003c id=         com.ibm.ws.security.token.ltpa.internal.LTPAKeyCreator       I CWWKS4105I: LTPA configuration is ready after 0.245 seconds.
[3/20/17 15:29:32:615 CDT] 0000003f id=         com.ibm.ws.tcpchannel.internal.TCPChannel                    I CWWKO0219I: TCP Channel defaultHttpEndpoint has been started and is now listening for requests on host 127.0.0.1  (IPv4: 127.0.0.1) port 8080.
[3/20/17 15:29:34:449 CDT] 0000001d id=         com.ibm.ws.sib.utils.ras.SibMessage                          I  CWSID0108I: JMS server has started.  
[3/20/17 15:29:34:487 CDT] 0000001d id=         com.ibm.ws.tcpchannel.internal.TCPChannel                    I CWWKO0219I: TCP Channel wasJmsEndpoint480 has been started and is now listening for requests on host 127.0.0.1  (IPv4: 127.0.0.1) port 7276.
[3/20/17 15:29:34:619 CDT] 0000001d id=         com.ibm.ws.cache.ServerCache                                 I DYNA1001I: WebSphere Dynamic Cache instance named baseCache initialized successfully.
[3/20/17 15:29:34:620 CDT] 0000001d id=         com.ibm.ws.cache.ServerCache                                 I DYNA1071I: The cache provider default is being used.
[3/20/17 15:29:34:620 CDT] 0000001d id=         com.ibm.ws.cache.CacheServiceImpl                            I DYNA1056I: Dynamic Cache (object cache) initialized successfully.
[3/20/17 15:29:35:318 CDT] 0000005d id=         com.ibm.ws.http.internal.VirtualHostImpl                     A CWWKT0016I: Web application available (default_host): http://localhost:8080/SpringProject/
[3/20/17 15:29:35:322 CDT] 0000005d id=         com.ibm.ws.app.manager.AppMessageHelper                      A CWWKZ0001I: Application SpringProject started in 0.302 seconds.
[3/20/17 15:29:35:328 CDT] 00000027 id=         com.ibm.ws.kernel.feature.internal.FeatureManager            A CWWKF0012I: The server installed the following features: [mdb-3.2, localConnector-1.0, webProfile-7.0, json-1.0, jaxrs-2.0, appSecurity-2.0, jpa-2.1, jaspic-1.1, distributedMap-1.0, jaxb-2.2, jaxws-2.2, ssl-1.0, jdbc-4.1, managedBeans-1.0, jsf-2.2, appClientSupport-1.0, jacc-1.5, ejbHome-3.2, wasJmsClient-2.0, cdi-1.2, wasJmsSecurity-1.0, jaxrsClient-2.0, ejbRemote-3.2, javaMail-1.5, batch-1.0, j2eeManagement-1.1, websocket-1.1, el-3.0, beanValidation-1.1, ejbPersistentTimer-3.2, jca-1.7, wasJmsServer-1.0, servlet-3.1, ejb-3.2, jsp-2.3, jndi-1.0, jsonp-1.0, concurrent-1.0, ejbLite-3.2, jcaInboundSecurity-1.0, javaee-7.0].
[3/20/17 15:29:35:329 CDT] 00000027 id=         com.ibm.ws.kernel.feature.internal.FeatureManager            A CWWKF0011I: The server server2 is ready to run a smarter planet.
 [3/20/17 15:29:36:368 CDT] 0000006b id=         com.ibm.ws.cache.CacheServiceImpl                            I DYNA1056I: Dynamic Cache (object cache) initialized successfully.
[3/20/17 15:29:44:733 CDT] 00000045 id=         ibm.ws.transport.iiop.security.AbstractCsiv2SubsystemFactory E CWWKS9582E: The [defaultSSLConfig] sslRef attributes required by the orb element with the defaultOrb id have not been resolved within 10 seconds. As a result, the applications will not start. Ensure that you have included a keyStore element and that Secure Sockets Layer (SSL) is configured correctly. If the sslRef is defaultSSLConfig, then add a keyStore element with the id defaultKeyStore and a password.

这是我的项目结构

编辑-4我有下面的项目方面

我有jdk 7

EN

回答 2

Stack Overflow用户

发布于 2017-03-21 12:24:51

据我所知,您应该告诉spring在哪里细化配置类;您是否尝试了以下操作:

代码语言:javascript
复制
package com.spring.config;
public class AppInitializer implements WebApplicationInitializer {  

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    // Create the 'root' Spring application context
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.scan("com.spring");
    rootContext.setConfigLocations(YOUR SPRING CFG FULL QUALIFIED CLASSES );

    // Manages the lifecycle of the root application context
    servletContext.addListener(new ContextLoaderListener(rootContext));

    // Declare dispatcher servlet. Handles requests into the application
    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher",
            new DispatcherServlet(rootContext));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");
}
}

试着看看这里的AnnotationConfigWebApplicationContextAbstractRefreshableConfigApplicationContext

票数 1
EN

Stack Overflow用户

发布于 2017-03-27 15:50:25

这可能会引起问题,请更改

代码语言:javascript
复制
@RequestMapping(value = "/statuscheck", method = RequestMethod.GET)
    public @ResponseBody
    String getStatusCheck() {
        return "SUCCESS";
    }

代码语言:javascript
复制
@RequestMapping(value = "/statuscheck", method = RequestMethod.GET)
@ResponseBody
public String getStatusCheck() {
    return "SUCCESS";
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42848344

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档