2017-03-17 3 views
3

Ich versuche, ein einfaches Spring-Projekt zu starten, aber es scheint nicht zu funktionieren. Es gibt keine Fehler. Versucht, verschiedene Dinge zu ändern, aber kein Glück. Im Folgenden sind die KlassenDatei nicht gefunden Problem mit Spring-Projekt

AppInitializer.java

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

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`

package com.spring.config; 

import org.springframework.context.annotation.Configuration; 

@Configuration 

public class AppConfig { 

} 

HelloController.java

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

Ich habe feder Kontext (4.3.0-RELEASE), feder webmvc (4.3.0-RELEASE), javax.servlet -api, jstl als Abhängigkeiten.

Ich bin mit Websphere 8.5.5.9

Ich habe versucht, diese URL Überprüfung:

http://localhost:8080/SpringProject/statuscheck 

und ich bekam

[WARNING ] SRVE0190E: File not found: /statuscheck 

EDIT-1

I hav e dies in server.xml

<webApplication id="SpringProject" contextRoot = "SpringProject" location="SpringProject.war" name="SpringProject"/> 

EDIT-2

habe ich diesen Code in pom.xml .So Ich habe keine web.xml

<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> 

EDIT-3

Dies ist eine Protokolldatei.Ich sehe keine Probleme in log

[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. 

Das ist mein Projektstruktur

enter image description here

EDIT-4 ich habe, ist das unter Projektfacetten

enter image description here

Ich habe JDK 7

enter image description here

+1

Überprüfen Sie den Kontextstamm in Ihrer server.xml –

+0

javaMan

+1

Was ist, wenn Sie versuchen - http: // localhost: 8080/SpringProject /? –

Antwort

1

Soweit ich weiß, Sie sollten Frühling sagen, wo die Konfigurationsklasse fein; haben Sie folgendes versuchen:

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("/"); 
} 
} 

versuchen, einen Blick hier AnnotationConfigWebApplicationContext und hier AbstractRefreshableConfigApplicationContext

+0

Ich habe diese Zeile hinzugefügt Es hat nicht funktioniert: \t rootContext.setConfigLocations ("com.spring.config.WebAppContextConfig"); – javaMan

+1

Hier https://github.com/angeloimm/stackoverflow/tree/master/SpringStack findest du ein einfaches Beispiel, das du mit deinen Klassen gemacht hast. Ich habe Tomcat 8.5 benutzt und alles funktioniert ziemlich gut. Die Zugangs-URL ist http: // localhost: 8080/SpringStack/ –

+0

Hallo .. Ich habe Ihren Code heruntergeladen und lokal versucht .. Ich habe jdk 7 und websphere Liberty-Profil .. Also löschte ich Ihre Einstellungen und Classpath-Dateien. und schau bitte auf meinen EDIT -4. Ich frage mich, ob es mit meinem Projekt Facetten – javaMan

1

Dies könnte verursachen Problem zu geben, ändern Sie es

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

Um

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