亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

基于Spring MVC Java的配置無法正常工作控制臺顯示無錯誤,但我的jsp頁面未顯示

瀏覽:73日期:2024-05-13 13:56:48
(adsbygoogle = window.adsbygoogle || []).push({}); 如何解決基于Spring MVC Java的配置無法正常工作控制臺顯示無錯誤,但我的jsp頁面未顯示?

謝謝您的回答。我發現了問題。當我在MvcConfiguration類的頂部編寫@ComponentScan時,它起作用了,并且正在顯示頁面。

解決方法

您好,我正在將我的簡單演示項目從Bean配置轉換為基于純Java的配置。Bean配置可以很好地創建表和所有表。但是我的Java配置未顯示任何頁面。我解決了許多錯誤bur,現在控制臺顯示指定問題沒有錯誤。這是我的代碼,請查找出什么問題,或者我錯過了配置中的任何內容。我是spring的新手,也是基于java的配置的新手。這些是我從中獲取代碼的網站。

http://codehustler.org/blog/spring-security-tutorial-form-login-java-config/

對于hibernate,我使用本教程

http://websystique.com/spring/spring4-hibernate4-mysql-maven-integration-example-using-annotations/

我的課程

1. AppConfiguration package com.kharoud.configuration; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @Configuration @ComponentScan({'com.kharoud'}) @Import({MvcConfiguraion.class,RepositoryConfiguration.class}) public class AppConfiguration { }

2.Mvc配置

package com.kharoud.configuration;import org.springframework.beans.factory.annotation.Configurable;import org.springframework.context.annotation.Bean;import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;import org.springframework.web.servlet.config.annotation.EnableWebMvc;import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;import org.springframework.web.servlet.view.InternalResourceViewResolver;@EnableWebMvc@Configurationpublic class MvcConfiguraion extends WebMvcConfigurerAdapter{@Overridepublic void configureDefaultServletHandling( DefaultServletHandlerConfigurer configurer ){ configurer.enable();}@Beanpublic InternalResourceViewResolver getInternalResourceViewResolver(){ InternalResourceViewResolver resolver = new InternalResourceViewResolver(); resolver.setPrefix('/WEB-INF/views'); resolver.setSuffix('.jsp'); return resolver;}}

3.RepositoryConfiguration包com.kharoud.configuration;

import java.util.Properties;import javax.sql.DataSource;import org.hibernate.SessionFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.context.annotation.PropertySource;import org.springframework.core.env.Environment;import org.springframework.jdbc.datasource.DriverManagerDataSource;import org.springframework.orm.hibernate4.HibernateTransactionManager;import org.springframework.orm.hibernate4.LocalSessionFactoryBean;import org.springframework.transaction.annotation.EnableTransactionManagement;@Configuration@EnableTransactionManagement@PropertySource({ 'classpath:hibernate.properties' })public class RepositoryConfiguration {@Autowiredprivate Environment environment;@Beanpublic LocalSessionFactoryBean sessionFactory(){ LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean(); sessionFactory.setDataSource(dataSource()); sessionFactory.setPackagesToScan(new String[] {'com.kharoud.model'}); sessionFactory.setHibernateProperties(hibernateProperties()); return sessionFactory;}@Beanpublic Properties hibernateProperties() { Properties properties = new Properties(); properties.put('hibernate.dialect',environment.getRequiredProperty('hibernate.dialect')); properties.put('hibernate.show_sql',environment.getRequiredProperty('hibernate.show_sql')); properties.put('hibernate.hbm2ddl.auto',environment.getRequiredProperty('hibernate.hbm2ddl.auto')); return properties;}@Beanpublic DataSource dataSource() { DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName(environment.getRequiredProperty('jdbc.driverClassName')); dataSource.setUrl(environment.getRequiredProperty('jdbc.url')); dataSource.setUsername(environment.getRequiredProperty('jdbc.username')); dataSource.setPassword(environment.getRequiredProperty('jdbc.password')); return dataSource;}@Bean@Autowiredpublic HibernateTransactionManager transactionManager(SessionFactory s) { HibernateTransactionManager txManager = new HibernateTransactionManager(); txManager.setSessionFactory(s); return txManager;}}

4,SpringConfigurationInitializer

package com.kharoud.configuration.initilizer;import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;import com.kharoud.configuration.AppConfiguration;public class SpringConfigurationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer{@Overrideprotected Class<?>[] getRootConfigClasses() { return new Class[] { AppConfiguration.class };}@Overrideprotected Class<?>[] getServletConfigClasses() { // TODO Auto-generated method stub return null;}@Overrideprotected String[] getServletMappings() { return new String[] { '/' };}}

只添加了這些新類。我刪除了我的web.xml。

稍后我將添加Spring Security配置類

這是我的控制臺輸出

Feb 25,2015 2:32:13 PM org.apache.catalina.core.AprLifecycleListener initINFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:Program FilesJavajdk1.8.0_25bin;C:WindowsSunJavabin;C:Windowssystem32;C:Window s;C:/Program Files/Java/jre1.8.0_25/bin/server;C:/Program Files/Java/jre1.8.0_25/bin;C:/Program Files/Java/jre1.8.0_25/lib/amd64;C:ProgramDataOracleJavajavapath;C:Windows system32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShe llv1.0;C:Program FilesJavajdk1.8.0_25bin;;C:ECLIPSEeclipse;;. Feb 25,2015 2:32:14 PM org.apache.tomcat.util.digester.SetPropertiesRule begin WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property ’source’ to ’org.eclipse.jst.jee.server:ProjectDemo’ did not find a matching property.Feb 25,2015 2:32:14 PM org.apache.coyote.AbstractProtocol initINFO: Initializing ProtocolHandler ['http-bio-8080']Feb 25,2015 2:32:14 PM org.apache.coyote.AbstractProtocol initINFO: Initializing ProtocolHandler ['ajp-bio-8009']Feb 25,2015 2:32:14 PM org.apache.catalina.startup.Catalina loadINFO: Initialization processed in 1063 msFeb 25,2015 2:32:14 PM org.apache.catalina.core.StandardService startInternalINFO: Starting service CatalinaFeb 25,2015 2:32:14 PM org.apache.catalina.core.StandardEngine startInternalINFO: Starting Servlet Engine: Apache Tomcat/7.0.47Feb 25,2015 2:32:15 PM org.apache.catalina.util.SessionIdGenerator createSecureRandomINFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [217] milliseconds.Feb 25,2015 2:32:18 PM org.apache.catalina.core.ApplicationContext logINFO: Spring WebApplicationInitializers detected on classpath: [com.kharoud.configuration.initilizer.SpringConfigurationInitializer@389ae113]Feb 25,2015 2:32:18 PM org.apache.catalina.core.ApplicationContext logINFO: Initializing Spring root WebApplicationContextlog4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).log4j:WARN Please initialize the log4j system properly.Feb 25,2015 2:32:26 PM org.apache.catalina.core.ApplicationContext logINFO: Initializing Spring FrameworkServlet ’dispatcher’Feb 25,2015 2:32:26 PM org.apache.coyote.AbstractProtocol startINFO: Starting ProtocolHandler ['http-bio-8080']Feb 25,2015 2:32:26 PM org.apache.coyote.AbstractProtocol startINFO: Starting ProtocolHandler ['ajp-bio-8009']Feb 25,2015 2:32:26 PM org.apache.catalina.startup.Catalina startINFO: Server startup in 11876 ms

MyHomeController

package com.kharoud;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;@Controllerpublic class HomeController { @RequestMapping('/') public String welcome(Model model){return 'index'; }}

Myindex.jsp文件位于webapp文件夾下的WEB-INF / views文件夾中

The views were properly resolved with bean configuration.

標簽: java
主站蜘蛛池模板: 国产一区二区三区在线视频 | 中文字幕一区二区区免 | 麻豆传媒网站入口直接进入免费版 | 精品视频午夜一区二区 | 久久国产精品女 | 亚洲综合一 | 中日韩欧美视频 | 特级毛片a级毛免费播放 | 一级黄色片免费观看 | 国产亚洲一区二区精品 | 麻豆传媒官网入口 | 精品成人乱色一区二区 | 国产欧美日本在线观看 | 综合久青草视频 | 一区二区三区四区在线观看视频 | 免费观看日本高清a毛片 | 久久精品国产亚洲麻豆小说 | 国产精品亚洲欧美一级久久精品 | 黑人和黑人一级毛片 | 亚洲精品99久久久久中文字幕 | 中文字幕欧美日韩高清 | xxx国产 | 亚洲精品在线网 | sese在线观看 | 久久免费精彩视频 | 婷婷黄色网 | 免费在线看黄视频 | 巨胸美女扒开腿让我爽 | 在线免费观看色视频 | 国产精品美女一区二区三区 | 女人18毛片久久鬼色 | 国产精品视频一区二区三区不卡 | 欧美在线a级高清 | 国产精品久久久久久免费 | 日韩a级毛片免费视频 | 亚洲精品一线观看 | 青草草在线观看 | 欧美黑人性猛交╳xx╳动态图 | 香蕉视频免费看 | 亚洲国产美女精品久久 | 国产剧情第一页 |