fork download
  1. package com.config;
  2.  
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.context.annotation.Bean;
  5. import org.springframework.context.annotation.ComponentScan;
  6. import org.springframework.context.annotation.Configuration;
  7. import org.springframework.context.annotation.PropertySource;
  8. import org.springframework.context.support.ResourceBundleMessageSource;
  9. import org.springframework.core.env.Environment;
  10. import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  11. import org.springframework.jdbc.datasource.DriverManagerDataSource;
  12. import org.springframework.orm.jpa.JpaTransactionManager;
  13. import org.springframework.orm.jpa.JpaVendorAdapter;
  14. import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
  15. import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
  16. import org.springframework.transaction.PlatformTransactionManager;
  17. import org.springframework.transaction.annotation.EnableTransactionManagement;
  18. import org.springframework.web.servlet.ViewResolver;
  19. import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
  20. import org.springframework.web.servlet.config.annotation.EnableWebMvc;
  21. import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
  22. import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
  23. import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
  24. import org.springframework.web.servlet.i18n.SessionLocaleResolver;
  25. import org.springframework.web.servlet.view.InternalResourceViewResolver;
  26. import org.springframework.web.servlet.view.JstlView;
  27.  
  28. import javax.persistence.EntityManagerFactory;
  29. import javax.sql.DataSource;
  30. import java.util.Locale;
  31. import java.util.Properties;
  32.  
  33. @Configuration
  34. @EnableWebMvc
  35. @ComponentScan(basePackages = {"com"})
  36. @EnableTransactionManagement
  37. @EnableJpaRepositories(basePackages = {"com"})
  38. @PropertySource("classpath:application.properties")
  39.  
  40. public class MVConfig extends WebMvcConfigurerAdapter {
  41. @Bean
  42. public ViewResolver viewResolver (){
  43. InternalResourceViewResolver internalResourceViewResolver = new InternalResourceViewResolver();
  44. internalResourceViewResolver.setViewClass(JstlView.class);
  45. internalResourceViewResolver.setPrefix("/WEB-INF/jsp/");
  46. internalResourceViewResolver.setSuffix(".jsp");
  47. return internalResourceViewResolver;
  48. }
  49. @Autowired
  50. private Environment environment;
  51.  
  52. @Bean
  53. LocaleChangeInterceptor localeChangeInterceptor()
  54. {
  55. LocaleChangeInterceptor localeChangeInterceptor= new LocaleChangeInterceptor();
  56. localeChangeInterceptor.setParamName("language");
  57. return localeChangeInterceptor;
  58. }
  59.  
  60. @Override
  61. public void addInterceptors(InterceptorRegistry registry) {
  62. registry.addInterceptor(localeChangeInterceptor());
  63. }
  64.  
  65.  
  66. @Bean
  67. SessionLocaleResolver localeResolver()
  68. {
  69. SessionLocaleResolver localeResolver = new SessionLocaleResolver() ;
  70. localeResolver.setDefaultLocale(new Locale("en"));
  71. return localeResolver;
  72. }
  73.  
  74. @Bean
  75. ResourceBundleMessageSource messageSource(){
  76. ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
  77. messageSource.setBasename("tableData");
  78. return messageSource;
  79. }
  80.  
  81. @Bean
  82. public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
  83. LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
  84. em.setDataSource(dataSource());
  85. em.setPackagesToScan(new String[] { "com" });
  86.  
  87. JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
  88. em.setJpaVendorAdapter(vendorAdapter);
  89. em.setJpaProperties(hibernateProperties());
  90.  
  91. return em;
  92. }
  93. @Bean
  94. public DataSource dataSource(){
  95. DriverManagerDataSource dataSource = new DriverManagerDataSource();
  96. dataSource.setDriverClassName("com.mysql.jdbc.Driver");
  97. dataSource.setUrl("jdbc:mysql://localhost:3306/orange");
  98. dataSource.setUsername( "root" );
  99. dataSource.setPassword( "root" );
  100. return dataSource;
  101. }
  102. private Properties hibernateProperties()
  103. {
  104. Properties properties = new Properties();
  105. properties.put("hibernate.dialect", environment.getRequiredProperty("hibernate.dialect"));
  106. properties.put("hibernate.show_sql", environment.getRequiredProperty("hibernate.show_sql"));
  107. properties.put("hibernate.format_sql", environment.getRequiredProperty("hibernate.format_sql"));
  108. properties.put("hibernate.hbm2ddl.auto", "create");
  109. properties.put("hibernate.enable_lazy_load_no_trans","true");
  110. return properties;
  111. }
  112.  
  113. @Bean
  114. @Autowired
  115. public PlatformTransactionManager transactionManager(EntityManagerFactory emf){
  116. JpaTransactionManager transactionManager = new JpaTransactionManager();
  117. transactionManager.setEntityManagerFactory(emf);
  118. return transactionManager;
  119. }
  120. @Override
  121. public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
  122. configurer.enable();
  123. }
  124. }
  125.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:40: error: class MVConfig is public, should be declared in a file named MVConfig.java
public class MVConfig extends WebMvcConfigurerAdapter {
       ^
Main.java:3: error: package org.springframework.beans.factory.annotation does not exist
import org.springframework.beans.factory.annotation.Autowired;
                                                   ^
Main.java:4: error: package org.springframework.context.annotation does not exist
import org.springframework.context.annotation.Bean;
                                             ^
Main.java:5: error: package org.springframework.context.annotation does not exist
import org.springframework.context.annotation.ComponentScan;
                                             ^
Main.java:6: error: package org.springframework.context.annotation does not exist
import org.springframework.context.annotation.Configuration;
                                             ^
Main.java:7: error: package org.springframework.context.annotation does not exist
import org.springframework.context.annotation.PropertySource;
                                             ^
Main.java:8: error: package org.springframework.context.support does not exist
import org.springframework.context.support.ResourceBundleMessageSource;
                                          ^
Main.java:9: error: package org.springframework.core.env does not exist
import org.springframework.core.env.Environment;
                                   ^
Main.java:10: error: package org.springframework.data.jpa.repository.config does not exist
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
                                                     ^
Main.java:11: error: package org.springframework.jdbc.datasource does not exist
import org.springframework.jdbc.datasource.DriverManagerDataSource;
                                          ^
Main.java:12: error: package org.springframework.orm.jpa does not exist
import org.springframework.orm.jpa.JpaTransactionManager;
                                  ^
Main.java:13: error: package org.springframework.orm.jpa does not exist
import org.springframework.orm.jpa.JpaVendorAdapter;
                                  ^
Main.java:14: error: package org.springframework.orm.jpa does not exist
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
                                  ^
Main.java:15: error: package org.springframework.orm.jpa.vendor does not exist
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
                                         ^
Main.java:16: error: package org.springframework.transaction does not exist
import org.springframework.transaction.PlatformTransactionManager;
                                      ^
Main.java:17: error: package org.springframework.transaction.annotation does not exist
import org.springframework.transaction.annotation.EnableTransactionManagement;
                                                 ^
Main.java:18: error: package org.springframework.web.servlet does not exist
import org.springframework.web.servlet.ViewResolver;
                                      ^
Main.java:19: error: package org.springframework.web.servlet.config.annotation does not exist
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
                                                        ^
Main.java:20: error: package org.springframework.web.servlet.config.annotation does not exist
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
                                                        ^
Main.java:21: error: package org.springframework.web.servlet.config.annotation does not exist
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
                                                        ^
Main.java:22: error: package org.springframework.web.servlet.config.annotation does not exist
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
                                                        ^
Main.java:23: error: package org.springframework.web.servlet.i18n does not exist
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
                                           ^
Main.java:24: error: package org.springframework.web.servlet.i18n does not exist
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
                                           ^
Main.java:25: error: package org.springframework.web.servlet.view does not exist
import org.springframework.web.servlet.view.InternalResourceViewResolver;
                                           ^
Main.java:26: error: package org.springframework.web.servlet.view does not exist
import org.springframework.web.servlet.view.JstlView;
                                           ^
Main.java:28: error: package javax.persistence does not exist
import javax.persistence.EntityManagerFactory;
                        ^
Main.java:40: error: cannot find symbol
public class MVConfig extends WebMvcConfigurerAdapter {
                              ^
  symbol: class WebMvcConfigurerAdapter
Main.java:33: error: cannot find symbol
@Configuration
 ^
  symbol: class Configuration
Main.java:34: error: cannot find symbol
@EnableWebMvc
 ^
  symbol: class EnableWebMvc
Main.java:35: error: cannot find symbol
@ComponentScan(basePackages = {"com"})
 ^
  symbol: class ComponentScan
Main.java:36: error: cannot find symbol
@EnableTransactionManagement
 ^
  symbol: class EnableTransactionManagement
Main.java:37: error: cannot find symbol
@EnableJpaRepositories(basePackages = {"com"})
 ^
  symbol: class EnableJpaRepositories
Main.java:38: error: cannot find symbol
@PropertySource("classpath:application.properties")
 ^
  symbol: class PropertySource
Main.java:42: error: cannot find symbol
    public ViewResolver viewResolver (){
           ^
  symbol:   class ViewResolver
  location: class MVConfig
Main.java:50: error: cannot find symbol
    private Environment environment;
            ^
  symbol:   class Environment
  location: class MVConfig
Main.java:53: error: cannot find symbol
    LocaleChangeInterceptor localeChangeInterceptor()
    ^
  symbol:   class LocaleChangeInterceptor
  location: class MVConfig
Main.java:61: error: cannot find symbol
    public void addInterceptors(InterceptorRegistry registry) {
                                ^
  symbol:   class InterceptorRegistry
  location: class MVConfig
Main.java:67: error: cannot find symbol
    SessionLocaleResolver localeResolver()
    ^
  symbol:   class SessionLocaleResolver
  location: class MVConfig
Main.java:75: error: cannot find symbol
    ResourceBundleMessageSource messageSource(){
    ^
  symbol:   class ResourceBundleMessageSource
  location: class MVConfig
Main.java:82: error: cannot find symbol
    public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
           ^
  symbol:   class LocalContainerEntityManagerFactoryBean
  location: class MVConfig
Main.java:115: error: cannot find symbol
    public PlatformTransactionManager transactionManager(EntityManagerFactory emf){
                                                         ^
  symbol:   class EntityManagerFactory
  location: class MVConfig
Main.java:115: error: cannot find symbol
    public PlatformTransactionManager transactionManager(EntityManagerFactory emf){
           ^
  symbol:   class PlatformTransactionManager
  location: class MVConfig
Main.java:121: error: cannot find symbol
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
                                                ^
  symbol:   class DefaultServletHandlerConfigurer
  location: class MVConfig
Main.java:41: error: cannot find symbol
    @Bean
     ^
  symbol:   class Bean
  location: class MVConfig
Main.java:49: error: cannot find symbol
    @Autowired
     ^
  symbol:   class Autowired
  location: class MVConfig
Main.java:52: error: cannot find symbol
    @Bean
     ^
  symbol:   class Bean
  location: class MVConfig
Main.java:66: error: cannot find symbol
    @Bean
     ^
  symbol:   class Bean
  location: class MVConfig
Main.java:74: error: cannot find symbol
    @Bean
     ^
  symbol:   class Bean
  location: class MVConfig
Main.java:81: error: cannot find symbol
    @Bean
     ^
  symbol:   class Bean
  location: class MVConfig
Main.java:93: error: cannot find symbol
    @Bean
     ^
  symbol:   class Bean
  location: class MVConfig
Main.java:113: error: cannot find symbol
    @Bean
     ^
  symbol:   class Bean
  location: class MVConfig
Main.java:114: error: cannot find symbol
    @Autowired
     ^
  symbol:   class Autowired
  location: class MVConfig
Main.java:43: error: cannot find symbol
        InternalResourceViewResolver internalResourceViewResolver = new InternalResourceViewResolver();
        ^
  symbol:   class InternalResourceViewResolver
  location: class MVConfig
Main.java:43: error: cannot find symbol
        InternalResourceViewResolver internalResourceViewResolver = new InternalResourceViewResolver();
                                                                        ^
  symbol:   class InternalResourceViewResolver
  location: class MVConfig
Main.java:44: error: cannot find symbol
        internalResourceViewResolver.setViewClass(JstlView.class);
                                                  ^
  symbol:   class JstlView
  location: class MVConfig
Main.java:55: error: cannot find symbol
        LocaleChangeInterceptor  localeChangeInterceptor= new LocaleChangeInterceptor();
        ^
  symbol:   class LocaleChangeInterceptor
  location: class MVConfig
Main.java:55: error: cannot find symbol
        LocaleChangeInterceptor  localeChangeInterceptor= new LocaleChangeInterceptor();
                                                              ^
  symbol:   class LocaleChangeInterceptor
  location: class MVConfig
Main.java:60: error: method does not override or implement a method from a supertype
    @Override
    ^
Main.java:69: error: cannot find symbol
        SessionLocaleResolver localeResolver = new SessionLocaleResolver() ;
        ^
  symbol:   class SessionLocaleResolver
  location: class MVConfig
Main.java:69: error: cannot find symbol
        SessionLocaleResolver localeResolver = new SessionLocaleResolver() ;
                                                   ^
  symbol:   class SessionLocaleResolver
  location: class MVConfig
Main.java:76: error: cannot find symbol
        ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
        ^
  symbol:   class ResourceBundleMessageSource
  location: class MVConfig
Main.java:76: error: cannot find symbol
        ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
                                                        ^
  symbol:   class ResourceBundleMessageSource
  location: class MVConfig
Main.java:83: error: cannot find symbol
        LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
        ^
  symbol:   class LocalContainerEntityManagerFactoryBean
  location: class MVConfig
Main.java:83: error: cannot find symbol
        LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
                                                        ^
  symbol:   class LocalContainerEntityManagerFactoryBean
  location: class MVConfig
Main.java:87: error: cannot find symbol
        JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
        ^
  symbol:   class JpaVendorAdapter
  location: class MVConfig
Main.java:87: error: cannot find symbol
        JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
                                             ^
  symbol:   class HibernateJpaVendorAdapter
  location: class MVConfig
Main.java:95: error: cannot find symbol
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        ^
  symbol:   class DriverManagerDataSource
  location: class MVConfig
Main.java:95: error: cannot find symbol
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
                                                 ^
  symbol:   class DriverManagerDataSource
  location: class MVConfig
Main.java:116: error: cannot find symbol
        JpaTransactionManager transactionManager = new JpaTransactionManager();
        ^
  symbol:   class JpaTransactionManager
  location: class MVConfig
Main.java:116: error: cannot find symbol
        JpaTransactionManager transactionManager = new JpaTransactionManager();
                                                       ^
  symbol:   class JpaTransactionManager
  location: class MVConfig
Main.java:120: error: method does not override or implement a method from a supertype
    @Override
    ^
71 errors
stdout
Standard output is empty