From 76351a44eae68b453582b8c03dec2dd0f580ca82 Mon Sep 17 00:00:00 2001 From: eugenp Date: Sun, 14 Jul 2013 14:48:25 +0300 Subject: [PATCH] spring all project --- spring-all/.classpath | 37 +++ spring-all/.gitignore | 13 ++ spring-all/.project | 60 +++++ spring-all/.settings/.jsdtscope | 12 + .../.settings/org.eclipse.jdt.core.prefs | 95 ++++++++ spring-all/.settings/org.eclipse.jdt.ui.prefs | 55 +++++ .../.settings/org.eclipse.m2e.core.prefs | 4 + .../.settings/org.eclipse.m2e.wtp.prefs | 2 + .../org.eclipse.wst.common.component | 10 + ....eclipse.wst.common.project.facet.core.xml | 6 + ...rg.eclipse.wst.jsdt.ui.superType.container | 1 + .../org.eclipse.wst.jsdt.ui.superType.name | 1 + .../org.eclipse.wst.validation.prefs | 14 ++ .../org.eclipse.wst.ws.service.policy.prefs | 2 + spring-all/.springBeans | 14 ++ spring-all/README.md | 13 ++ spring-all/pom.xml | 221 ++++++++++++++++++ .../cause1/BeanA.java | 12 + .../cause1/BeanB.java | 5 + .../cause2/BeanA.java | 12 + .../cause2/BeanB1.java | 8 + .../cause2/BeanB2.java | 8 + .../cause2/IBeanB.java | 5 + .../cause3/BeanA.java | 19 ++ .../spring/Cause1ContextWithJavaConfig.java | 16 ++ .../spring/Cause2ContextWithJavaConfig.java | 16 ++ .../spring/Cause3ContextWithJavaConfig.java | 16 ++ .../java/org/baeldung/persistence/Setup.java | 26 +++ .../core/ComponentInXmlUsingProperties.java | 30 +++ .../core/ComponentUsingProperties.java | 30 +++ .../spring/PropertiesWithJavaConfig.java | 25 ++ .../spring/PropertiesWithJavaConfigOther.java | 16 ++ .../spring/PropertiesWithXmlConfig.java | 16 ++ .../spring/PropertiesWithXmlConfigOne.java | 16 ++ .../spring/PropertiesWithXmlConfigTwo.java | 14 ++ .../baeldung/spring/config/CoreConfig.java | 15 ++ .../spring/config/MainWebAppInitializer.java | 41 ++++ .../org/baeldung/spring/config/MvcConfig.java | 39 ++++ .../spring/config/PersistenceConfig.java | 78 +++++++ spring-all/src/main/resources/bar.properties | 1 + .../main/resources/configForProperties.xml | 15 ++ .../main/resources/configForPropertiesOne.xml | 15 ++ .../main/resources/configForPropertiesTwo.xml | 11 + spring-all/src/main/resources/foo.properties | 1 + spring-all/src/main/resources/logback.xml | 22 ++ .../src/main/webapp/WEB-INF/mvc-servlet.xml | 6 + .../src/main/webapp/WEB-INF/view/sample.jsp | 7 + .../src/main/webapp/WEB-INF/web_old.xml | 42 ++++ ...eanDefinitionExceptionIntegrationTest.java | 19 ++ ...eanDefinitionExceptionIntegrationTest.java | 19 ++ ...eanDefinitionExceptionIntegrationTest.java | 19 ++ .../PropertiesWithJavaIntegrationTest.java | 30 +++ ...ertiesWithMultipleXmlsIntegrationTest.java | 30 +++ .../PropertiesWithXmlIntegrationTest.java | 29 +++ spring-all/src/test/resources/.gitignore | 13 ++ 55 files changed, 1302 insertions(+) create mode 100644 spring-all/.classpath create mode 100644 spring-all/.gitignore create mode 100644 spring-all/.project create mode 100644 spring-all/.settings/.jsdtscope create mode 100644 spring-all/.settings/org.eclipse.jdt.core.prefs create mode 100644 spring-all/.settings/org.eclipse.jdt.ui.prefs create mode 100644 spring-all/.settings/org.eclipse.m2e.core.prefs create mode 100644 spring-all/.settings/org.eclipse.m2e.wtp.prefs create mode 100644 spring-all/.settings/org.eclipse.wst.common.component create mode 100644 spring-all/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 spring-all/.settings/org.eclipse.wst.jsdt.ui.superType.container create mode 100644 spring-all/.settings/org.eclipse.wst.jsdt.ui.superType.name create mode 100644 spring-all/.settings/org.eclipse.wst.validation.prefs create mode 100644 spring-all/.settings/org.eclipse.wst.ws.service.policy.prefs create mode 100644 spring-all/.springBeans create mode 100644 spring-all/README.md create mode 100644 spring-all/pom.xml create mode 100644 spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause1/BeanA.java create mode 100644 spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause1/BeanB.java create mode 100644 spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause2/BeanA.java create mode 100644 spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause2/BeanB1.java create mode 100644 spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause2/BeanB2.java create mode 100644 spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause2/IBeanB.java create mode 100644 spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause3/BeanA.java create mode 100644 spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/spring/Cause1ContextWithJavaConfig.java create mode 100644 spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/spring/Cause2ContextWithJavaConfig.java create mode 100644 spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/spring/Cause3ContextWithJavaConfig.java create mode 100644 spring-all/src/main/java/org/baeldung/persistence/Setup.java create mode 100644 spring-all/src/main/java/org/baeldung/properties/core/ComponentInXmlUsingProperties.java create mode 100644 spring-all/src/main/java/org/baeldung/properties/core/ComponentUsingProperties.java create mode 100644 spring-all/src/main/java/org/baeldung/properties/spring/PropertiesWithJavaConfig.java create mode 100644 spring-all/src/main/java/org/baeldung/properties/spring/PropertiesWithJavaConfigOther.java create mode 100644 spring-all/src/main/java/org/baeldung/properties/spring/PropertiesWithXmlConfig.java create mode 100644 spring-all/src/main/java/org/baeldung/properties/spring/PropertiesWithXmlConfigOne.java create mode 100644 spring-all/src/main/java/org/baeldung/properties/spring/PropertiesWithXmlConfigTwo.java create mode 100644 spring-all/src/main/java/org/baeldung/spring/config/CoreConfig.java create mode 100644 spring-all/src/main/java/org/baeldung/spring/config/MainWebAppInitializer.java create mode 100644 spring-all/src/main/java/org/baeldung/spring/config/MvcConfig.java create mode 100644 spring-all/src/main/java/org/baeldung/spring/config/PersistenceConfig.java create mode 100644 spring-all/src/main/resources/bar.properties create mode 100644 spring-all/src/main/resources/configForProperties.xml create mode 100644 spring-all/src/main/resources/configForPropertiesOne.xml create mode 100644 spring-all/src/main/resources/configForPropertiesTwo.xml create mode 100644 spring-all/src/main/resources/foo.properties create mode 100644 spring-all/src/main/resources/logback.xml create mode 100644 spring-all/src/main/webapp/WEB-INF/mvc-servlet.xml create mode 100644 spring-all/src/main/webapp/WEB-INF/view/sample.jsp create mode 100644 spring-all/src/main/webapp/WEB-INF/web_old.xml create mode 100644 spring-all/src/test/java/org/baeldung/ex/nosuchbeandefinitionexception/Cause1NoSuchBeanDefinitionExceptionIntegrationTest.java create mode 100644 spring-all/src/test/java/org/baeldung/ex/nosuchbeandefinitionexception/Cause2NoSuchBeanDefinitionExceptionIntegrationTest.java create mode 100644 spring-all/src/test/java/org/baeldung/ex/nosuchbeandefinitionexception/Cause3NoSuchBeanDefinitionExceptionIntegrationTest.java create mode 100644 spring-all/src/test/java/org/baeldung/properties/core/PropertiesWithJavaIntegrationTest.java create mode 100644 spring-all/src/test/java/org/baeldung/properties/core/PropertiesWithMultipleXmlsIntegrationTest.java create mode 100644 spring-all/src/test/java/org/baeldung/properties/core/PropertiesWithXmlIntegrationTest.java create mode 100644 spring-all/src/test/resources/.gitignore diff --git a/spring-all/.classpath b/spring-all/.classpath new file mode 100644 index 0000000000..eed10d8a8b --- /dev/null +++ b/spring-all/.classpath @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-all/.gitignore b/spring-all/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/spring-all/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/spring-all/.project b/spring-all/.project new file mode 100644 index 0000000000..4ae82dabf0 --- /dev/null +++ b/spring-all/.project @@ -0,0 +1,60 @@ + + + spring-all + + + + + + org.eclipse.ui.externaltools.ExternalToolBuilder + full,incremental, + + + LaunchConfigHandle + <project>/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.zeroturnaround.eclipse.rebelXmlBuilder + + + + + org.springframework.ide.eclipse.core.springbuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.springframework.ide.eclipse.core.springnature + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.wst.jsdt.core.jsNature + org.zeroturnaround.eclipse.jrebelNature + + diff --git a/spring-all/.settings/.jsdtscope b/spring-all/.settings/.jsdtscope new file mode 100644 index 0000000000..b46b9207a8 --- /dev/null +++ b/spring-all/.settings/.jsdtscope @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/spring-all/.settings/org.eclipse.jdt.core.prefs b/spring-all/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..723e5b1245 --- /dev/null +++ b/spring-all/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,95 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore +org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull +org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault +org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable +org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.autoboxing=ignore +org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning +org.eclipse.jdt.core.compiler.problem.deadCode=warning +org.eclipse.jdt.core.compiler.problem.deprecation=warning +org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled +org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled +org.eclipse.jdt.core.compiler.problem.discouragedReference=warning +org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore +org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore +org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled +org.eclipse.jdt.core.compiler.problem.fieldHiding=error +org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning +org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning +org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled +org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning +org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore +org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore +org.eclipse.jdt.core.compiler.problem.localVariableHiding=error +org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning +org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore +org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled +org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled +org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning +org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore +org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning +org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning +org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore +org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error +org.eclipse.jdt.core.compiler.problem.nullReference=warning +org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error +org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning +org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning +org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore +org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore +org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore +org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore +org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning +org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning +org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore +org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore +org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore +org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore +org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore +org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled +org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning +org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled +org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled +org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore +org.eclipse.jdt.core.compiler.problem.typeParameterHiding=error +org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled +org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning +org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore +org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning +org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore +org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore +org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled +org.eclipse.jdt.core.compiler.problem.unusedImport=warning +org.eclipse.jdt.core.compiler.problem.unusedLabel=warning +org.eclipse.jdt.core.compiler.problem.unusedLocal=warning +org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled +org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning +org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning +org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/spring-all/.settings/org.eclipse.jdt.ui.prefs b/spring-all/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 0000000000..471e9b0d81 --- /dev/null +++ b/spring-all/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,55 @@ +#Sat Jan 21 23:04:06 EET 2012 +eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=true +sp_cleanup.add_missing_deprecated_annotations=true +sp_cleanup.add_missing_methods=false +sp_cleanup.add_missing_nls_tags=false +sp_cleanup.add_missing_override_annotations=true +sp_cleanup.add_missing_override_annotations_interface_methods=true +sp_cleanup.add_serial_version_id=false +sp_cleanup.always_use_blocks=true +sp_cleanup.always_use_parentheses_in_expressions=true +sp_cleanup.always_use_this_for_non_static_field_access=false +sp_cleanup.always_use_this_for_non_static_method_access=false +sp_cleanup.convert_to_enhanced_for_loop=true +sp_cleanup.correct_indentation=true +sp_cleanup.format_source_code=true +sp_cleanup.format_source_code_changes_only=true +sp_cleanup.make_local_variable_final=true +sp_cleanup.make_parameters_final=true +sp_cleanup.make_private_fields_final=false +sp_cleanup.make_type_abstract_if_missing_method=false +sp_cleanup.make_variable_declarations_final=true +sp_cleanup.never_use_blocks=false +sp_cleanup.never_use_parentheses_in_expressions=false +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=true +sp_cleanup.qualify_static_field_accesses_with_declaring_class=false +sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_with_declaring_class=true +sp_cleanup.qualify_static_method_accesses_with_declaring_class=false +sp_cleanup.remove_private_constructors=true +sp_cleanup.remove_trailing_whitespaces=true +sp_cleanup.remove_trailing_whitespaces_all=true +sp_cleanup.remove_trailing_whitespaces_ignore_empty=false +sp_cleanup.remove_unnecessary_casts=true +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=true +sp_cleanup.remove_unused_local_variables=false +sp_cleanup.remove_unused_private_fields=true +sp_cleanup.remove_unused_private_members=false +sp_cleanup.remove_unused_private_methods=true +sp_cleanup.remove_unused_private_types=true +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_parentheses_in_expressions=false +sp_cleanup.use_this_for_non_static_field_access=true +sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true +sp_cleanup.use_this_for_non_static_method_access=true +sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true diff --git a/spring-all/.settings/org.eclipse.m2e.core.prefs b/spring-all/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000000..f897a7f1cb --- /dev/null +++ b/spring-all/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/spring-all/.settings/org.eclipse.m2e.wtp.prefs b/spring-all/.settings/org.eclipse.m2e.wtp.prefs new file mode 100644 index 0000000000..ef86089622 --- /dev/null +++ b/spring-all/.settings/org.eclipse.m2e.wtp.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.m2e.wtp.enabledProjectSpecificPrefs=false diff --git a/spring-all/.settings/org.eclipse.wst.common.component b/spring-all/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000000..847c6ff698 --- /dev/null +++ b/spring-all/.settings/org.eclipse.wst.common.component @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/spring-all/.settings/org.eclipse.wst.common.project.facet.core.xml b/spring-all/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000000..a67649dfa5 --- /dev/null +++ b/spring-all/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/spring-all/.settings/org.eclipse.wst.jsdt.ui.superType.container b/spring-all/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000000..3bd5d0a480 --- /dev/null +++ b/spring-all/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/spring-all/.settings/org.eclipse.wst.jsdt.ui.superType.name b/spring-all/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000000..05bd71b6ec --- /dev/null +++ b/spring-all/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/spring-all/.settings/org.eclipse.wst.validation.prefs b/spring-all/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000000..cacf5451ae --- /dev/null +++ b/spring-all/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,14 @@ +DELEGATES_PREFERENCE=delegateValidatorList +USER_BUILD_PREFERENCE=enabledBuildValidatorListorg.eclipse.jst.j2ee.internal.classpathdep.ClasspathDependencyValidator; +USER_MANUAL_PREFERENCE=enabledManualValidatorListorg.eclipse.jst.j2ee.internal.classpathdep.ClasspathDependencyValidator; +USER_PREFERENCE=overrideGlobalPreferencestruedisableAllValidationfalseversion1.2.303.v201202090300 +eclipse.preferences.version=1 +override=true +suspend=false +vals/org.eclipse.jst.jsf.ui.JSFAppConfigValidator/global=FF01 +vals/org.eclipse.jst.jsp.core.JSPBatchValidator/global=FF01 +vals/org.eclipse.jst.jsp.core.JSPContentValidator/global=FF01 +vals/org.eclipse.jst.jsp.core.TLDValidator/global=FF01 +vals/org.eclipse.wst.dtd.core.dtdDTDValidator/global=FF01 +vals/org.eclipse.wst.jsdt.web.core.JsBatchValidator/global=TF02 +vf.version=3 diff --git a/spring-all/.settings/org.eclipse.wst.ws.service.policy.prefs b/spring-all/.settings/org.eclipse.wst.ws.service.policy.prefs new file mode 100644 index 0000000000..9cfcabe16f --- /dev/null +++ b/spring-all/.settings/org.eclipse.wst.ws.service.policy.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.wst.ws.service.policy.projectEnabled=false diff --git a/spring-all/.springBeans b/spring-all/.springBeans new file mode 100644 index 0000000000..7623a7e888 --- /dev/null +++ b/spring-all/.springBeans @@ -0,0 +1,14 @@ + + + 1 + + + + + + + src/main/webapp/WEB-INF/mvc-servlet.xml + + + + diff --git a/spring-all/README.md b/spring-all/README.md new file mode 100644 index 0000000000..0541922dc9 --- /dev/null +++ b/spring-all/README.md @@ -0,0 +1,13 @@ +========= + +## Spring Exceptions Example Project + +This project is used to replicate Spring Exceptions only. + + +### Relevant articles: +- [Spring BeanCreationException](http://www.baeldung.com/spring-beancreationexception) +- [Spring DataIntegrityViolationException](http://www.baeldung.com/spring-dataIntegrityviolationexception) +- [Spring BeanDefinitionStoreException](http://www.baeldung.com/spring-beandefinitionstoreexception) +- [Spring NoSuchBeanDefinitionException](http://www.baeldung.com/spring-nosuchbeandefinitionexception) +- [Properties with Spring](http://www.baeldung.com/2012/02/06/properties-with-spring) - checkout the `org.baeldung.properties` package for all scenarios of properties injection and usage \ No newline at end of file diff --git a/spring-all/pom.xml b/spring-all/pom.xml new file mode 100644 index 0000000000..9dfb42a623 --- /dev/null +++ b/spring-all/pom.xml @@ -0,0 +1,221 @@ + + 4.0.0 + org.baeldung + spring-all + 0.1-SNAPSHOT + + spring-all + war + + + + + + + org.springframework + spring-web + ${org.springframework.version} + + + org.springframework + spring-webmvc + ${org.springframework.version} + + + org.springframework + spring-orm + ${org.springframework.version} + + + org.springframework + spring-context + ${org.springframework.version} + + + + + + org.hibernate + hibernate-core + ${hibernate.version} + + + org.javassist + javassist + ${javassist.version} + + + mysql + mysql-connector-java + ${mysql-connector-java.version} + runtime + + + + + + org.hibernate + hibernate-validator + ${hibernate-validator.version} + + + + + + javax.servlet + javax.servlet-api + 3.0.1 + provided + + + + javax.servlet + jstl + ${jstl.version} + runtime + + + + + + com.google.guava + guava + ${guava.version} + + + + + + org.springframework + spring-test + ${org.springframework.version} + test + + + + junit + junit-dep + ${junit.version} + test + + + + org.hamcrest + hamcrest-core + ${org.hamcrest.version} + test + + + org.hamcrest + hamcrest-library + ${org.hamcrest.version} + test + + + + org.mockito + mockito-core + ${mockito.version} + test + + + + + + spring-all + + + src/main/resources + true + + + + + + + org.apache.maven.plugins + maven-war-plugin + 2.3 + + false + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + + + + + + + + + + org.codehaus.cargo + cargo-maven2-plugin + ${cargo-maven2-plugin.version} + + true + + jetty8x + embedded + + + + + + + 8082 + + + + + + + + + + + + 3.2.3.RELEASE + 3.1.4.RELEASE + 3.18.0-GA + 1.2 + + + 4.2.2.Final + 5.1.25 + + + 1.7.5 + 1.0.11 + + + 5.0.1.Final + + + 14.0.1 + 3.1 + + + 1.3 + 4.11 + 1.9.5 + + 4.2.4 + 4.2.5 + + 1.8.1 + 1.8.9 + + + 1.4.2 + 2.15 + + + \ No newline at end of file diff --git a/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause1/BeanA.java b/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause1/BeanA.java new file mode 100644 index 0000000000..c664309426 --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause1/BeanA.java @@ -0,0 +1,12 @@ +package org.baeldung.ex.nosuchbeandefinitionexception.cause1; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class BeanA { + + @Autowired + private BeanB dependency; + +} \ No newline at end of file diff --git a/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause1/BeanB.java b/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause1/BeanB.java new file mode 100644 index 0000000000..8a198422e8 --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause1/BeanB.java @@ -0,0 +1,5 @@ +package org.baeldung.ex.nosuchbeandefinitionexception.cause1; + +public class BeanB { + // +} diff --git a/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause2/BeanA.java b/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause2/BeanA.java new file mode 100644 index 0000000000..2b454bfabb --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause2/BeanA.java @@ -0,0 +1,12 @@ +package org.baeldung.ex.nosuchbeandefinitionexception.cause2; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class BeanA { + + @Autowired + private IBeanB dependency; + +} \ No newline at end of file diff --git a/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause2/BeanB1.java b/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause2/BeanB1.java new file mode 100644 index 0000000000..877f400668 --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause2/BeanB1.java @@ -0,0 +1,8 @@ +package org.baeldung.ex.nosuchbeandefinitionexception.cause2; + +import org.springframework.stereotype.Component; + +@Component +public class BeanB1 implements IBeanB { + // +} \ No newline at end of file diff --git a/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause2/BeanB2.java b/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause2/BeanB2.java new file mode 100644 index 0000000000..6bf4160966 --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause2/BeanB2.java @@ -0,0 +1,8 @@ +package org.baeldung.ex.nosuchbeandefinitionexception.cause2; + +import org.springframework.stereotype.Component; + +@Component +public class BeanB2 implements IBeanB { + // +} \ No newline at end of file diff --git a/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause2/IBeanB.java b/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause2/IBeanB.java new file mode 100644 index 0000000000..3e70126c1a --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause2/IBeanB.java @@ -0,0 +1,5 @@ +package org.baeldung.ex.nosuchbeandefinitionexception.cause2; + +public interface IBeanB { + // +} diff --git a/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause3/BeanA.java b/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause3/BeanA.java new file mode 100644 index 0000000000..091d3f1aa8 --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/cause3/BeanA.java @@ -0,0 +1,19 @@ +package org.baeldung.ex.nosuchbeandefinitionexception.cause3; + +import org.springframework.beans.factory.InitializingBean; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.stereotype.Component; + +@Component +public class BeanA implements InitializingBean { + + @Autowired + private ApplicationContext context; + + @Override + public void afterPropertiesSet() { + context.getBean("someBeanName"); + } + +} \ No newline at end of file diff --git a/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/spring/Cause1ContextWithJavaConfig.java b/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/spring/Cause1ContextWithJavaConfig.java new file mode 100644 index 0000000000..5ba971baa9 --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/spring/Cause1ContextWithJavaConfig.java @@ -0,0 +1,16 @@ +package org.baeldung.ex.nosuchbeandefinitionexception.spring; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ComponentScan("org.baeldung.ex.nosuchbeandefinitionexception.cause1") +public class Cause1ContextWithJavaConfig { + + public Cause1ContextWithJavaConfig() { + super(); + } + + // beans + +} \ No newline at end of file diff --git a/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/spring/Cause2ContextWithJavaConfig.java b/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/spring/Cause2ContextWithJavaConfig.java new file mode 100644 index 0000000000..9f4816ef7c --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/spring/Cause2ContextWithJavaConfig.java @@ -0,0 +1,16 @@ +package org.baeldung.ex.nosuchbeandefinitionexception.spring; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ComponentScan("org.baeldung.ex.nosuchbeandefinitionexception.cause2") +public class Cause2ContextWithJavaConfig { + + public Cause2ContextWithJavaConfig() { + super(); + } + + // beans + +} \ No newline at end of file diff --git a/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/spring/Cause3ContextWithJavaConfig.java b/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/spring/Cause3ContextWithJavaConfig.java new file mode 100644 index 0000000000..a8d0fbe37b --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/ex/nosuchbeandefinitionexception/spring/Cause3ContextWithJavaConfig.java @@ -0,0 +1,16 @@ +package org.baeldung.ex.nosuchbeandefinitionexception.spring; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ComponentScan("org.baeldung.ex.nosuchbeandefinitionexception.cause3") +public class Cause3ContextWithJavaConfig { + + public Cause3ContextWithJavaConfig() { + super(); + } + + // beans + +} \ No newline at end of file diff --git a/spring-all/src/main/java/org/baeldung/persistence/Setup.java b/spring-all/src/main/java/org/baeldung/persistence/Setup.java new file mode 100644 index 0000000000..5cba4e70fb --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/persistence/Setup.java @@ -0,0 +1,26 @@ +package org.baeldung.persistence; + +import org.springframework.context.ApplicationListener; +import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.stereotype.Component; + +@Component +public class Setup implements ApplicationListener { + + private boolean setupDone; + + public Setup() { + super(); + } + + // + + @Override + public final void onApplicationEvent(final ContextRefreshedEvent event) { + if (!setupDone) { + System.out.println(); + setupDone = true; + } + } + +} diff --git a/spring-all/src/main/java/org/baeldung/properties/core/ComponentInXmlUsingProperties.java b/spring-all/src/main/java/org/baeldung/properties/core/ComponentInXmlUsingProperties.java new file mode 100644 index 0000000000..f695326cd6 --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/properties/core/ComponentInXmlUsingProperties.java @@ -0,0 +1,30 @@ +package org.baeldung.properties.core; + +import org.springframework.beans.factory.InitializingBean; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.env.Environment; + +public class ComponentInXmlUsingProperties implements InitializingBean { + + @Autowired + private Environment env; + + @Value("${key.something}") + private String injectedProperty; + + public ComponentInXmlUsingProperties(final String propertyValue) { + super(); + + System.out.println("Constructor Injection - Property Value resolted to: " + propertyValue); + } + + // + + @Override + public void afterPropertiesSet() throws Exception { + System.out.println("in afterPropertiesSet via @Value: " + injectedProperty); + System.out.println("in afterPropertiesSet Environment: " + env.getProperty("key.something")); + } + +} diff --git a/spring-all/src/main/java/org/baeldung/properties/core/ComponentUsingProperties.java b/spring-all/src/main/java/org/baeldung/properties/core/ComponentUsingProperties.java new file mode 100644 index 0000000000..7e082702fe --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/properties/core/ComponentUsingProperties.java @@ -0,0 +1,30 @@ +package org.baeldung.properties.core; + +import org.springframework.beans.factory.InitializingBean; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; + +@Component +public class ComponentUsingProperties implements InitializingBean { + + @Autowired + private Environment env; + + @Value("${key.something}") + private String injectedProperty; + + public ComponentUsingProperties() { + super(); + } + + // + + @Override + public void afterPropertiesSet() throws Exception { + System.out.println("in afterPropertiesSet via @Value: " + injectedProperty); + System.out.println("in afterPropertiesSet Environment: " + env.getProperty("key.something")); + } + +} diff --git a/spring-all/src/main/java/org/baeldung/properties/spring/PropertiesWithJavaConfig.java b/spring-all/src/main/java/org/baeldung/properties/spring/PropertiesWithJavaConfig.java new file mode 100644 index 0000000000..9b5d7ed047 --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/properties/spring/PropertiesWithJavaConfig.java @@ -0,0 +1,25 @@ +package org.baeldung.properties.spring; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; + +@Configuration +@ComponentScan("org.baeldung.properties.core") +@PropertySource("classpath:foo.properties") +public class PropertiesWithJavaConfig { + + public PropertiesWithJavaConfig() { + super(); + } + + // beans + + @Bean + public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { + return new PropertySourcesPlaceholderConfigurer(); + } + +} \ No newline at end of file diff --git a/spring-all/src/main/java/org/baeldung/properties/spring/PropertiesWithJavaConfigOther.java b/spring-all/src/main/java/org/baeldung/properties/spring/PropertiesWithJavaConfigOther.java new file mode 100644 index 0000000000..594ba0a09d --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/properties/spring/PropertiesWithJavaConfigOther.java @@ -0,0 +1,16 @@ +package org.baeldung.properties.spring; + +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; + +@Configuration +@PropertySource("classpath:bar.properties") +public class PropertiesWithJavaConfigOther { + + public PropertiesWithJavaConfigOther() { + super(); + } + + // beans + +} \ No newline at end of file diff --git a/spring-all/src/main/java/org/baeldung/properties/spring/PropertiesWithXmlConfig.java b/spring-all/src/main/java/org/baeldung/properties/spring/PropertiesWithXmlConfig.java new file mode 100644 index 0000000000..9ad7febcb0 --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/properties/spring/PropertiesWithXmlConfig.java @@ -0,0 +1,16 @@ +package org.baeldung.properties.spring; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportResource; + +@Configuration +@ImportResource("classpath:configForProperties.xml") +@ComponentScan("org.baeldung.core") +public class PropertiesWithXmlConfig { + + public PropertiesWithXmlConfig() { + super(); + } + +} \ No newline at end of file diff --git a/spring-all/src/main/java/org/baeldung/properties/spring/PropertiesWithXmlConfigOne.java b/spring-all/src/main/java/org/baeldung/properties/spring/PropertiesWithXmlConfigOne.java new file mode 100644 index 0000000000..9061cc10d4 --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/properties/spring/PropertiesWithXmlConfigOne.java @@ -0,0 +1,16 @@ +package org.baeldung.properties.spring; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportResource; + +@Configuration +@ImportResource("classpath:configForPropertiesOne.xml") +@ComponentScan("org.baeldung.core") +public class PropertiesWithXmlConfigOne { + + public PropertiesWithXmlConfigOne() { + super(); + } + +} \ No newline at end of file diff --git a/spring-all/src/main/java/org/baeldung/properties/spring/PropertiesWithXmlConfigTwo.java b/spring-all/src/main/java/org/baeldung/properties/spring/PropertiesWithXmlConfigTwo.java new file mode 100644 index 0000000000..e4365cbc8b --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/properties/spring/PropertiesWithXmlConfigTwo.java @@ -0,0 +1,14 @@ +package org.baeldung.properties.spring; + +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportResource; + +@Configuration +@ImportResource("classpath:configForPropertiesTwo.xml") +public class PropertiesWithXmlConfigTwo { + + public PropertiesWithXmlConfigTwo() { + super(); + } + +} \ No newline at end of file diff --git a/spring-all/src/main/java/org/baeldung/spring/config/CoreConfig.java b/spring-all/src/main/java/org/baeldung/spring/config/CoreConfig.java new file mode 100644 index 0000000000..ff1742351b --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/spring/config/CoreConfig.java @@ -0,0 +1,15 @@ +package org.baeldung.spring.config; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; + +@Configuration +@ComponentScan("org.baeldung.core") +public class CoreConfig extends WebMvcConfigurerAdapter { + + public CoreConfig() { + super(); + } + +} \ No newline at end of file diff --git a/spring-all/src/main/java/org/baeldung/spring/config/MainWebAppInitializer.java b/spring-all/src/main/java/org/baeldung/spring/config/MainWebAppInitializer.java new file mode 100644 index 0000000000..5ef83b8afd --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/spring/config/MainWebAppInitializer.java @@ -0,0 +1,41 @@ +package org.baeldung.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.context.support.GenericWebApplicationContext; +import org.springframework.web.servlet.DispatcherServlet; + +public class MainWebAppInitializer implements WebApplicationInitializer { + + /** + * Register and configure all Servlet container components necessary to power the web application. + */ + @Override + public void onStartup(final ServletContext sc) throws ServletException { + System.out.println("MainWebAppInitializer.onStartup()"); + + // Create the 'root' Spring application context + final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext(); + root.scan("org.baeldung.spring.config"); + // root.getEnvironment().setDefaultProfiles("embedded"); + + // Manages the lifecycle of the root application context + sc.addListener(new ContextLoaderListener(root)); + + // Handles requests into the application + final ServletRegistration.Dynamic appServlet = sc.addServlet("mvc", new DispatcherServlet(new GenericWebApplicationContext())); + appServlet.setLoadOnStartup(1); + final Set mappingConflicts = appServlet.addMapping("/"); + if (!mappingConflicts.isEmpty()) { + throw new IllegalStateException("'appServlet' could not be mapped to '/' due " + "to an existing mapping. This is a known issue under Tomcat versions " + "<= 7.0.14; see https://issues.apache.org/bugzilla/show_bug.cgi?id=51278"); + } + } + +} diff --git a/spring-all/src/main/java/org/baeldung/spring/config/MvcConfig.java b/spring-all/src/main/java/org/baeldung/spring/config/MvcConfig.java new file mode 100644 index 0000000000..f87e400fce --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/spring/config/MvcConfig.java @@ -0,0 +1,39 @@ +package org.baeldung.spring.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.ViewResolver; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.view.InternalResourceViewResolver; +import org.springframework.web.servlet.view.JstlView; + +@EnableWebMvc +@Configuration +public class MvcConfig extends WebMvcConfigurerAdapter { + + public MvcConfig() { + super(); + } + + // API + + @Override + public void addViewControllers(final ViewControllerRegistry registry) { + super.addViewControllers(registry); + + registry.addViewController("/sample.html"); + } + + @Bean + public ViewResolver viewResolver() { + final InternalResourceViewResolver bean = new InternalResourceViewResolver(); + + bean.setViewClass(JstlView.class); + bean.setPrefix("/WEB-INF/view/"); + bean.setSuffix(".jsp"); + + return bean; + } +} \ No newline at end of file diff --git a/spring-all/src/main/java/org/baeldung/spring/config/PersistenceConfig.java b/spring-all/src/main/java/org/baeldung/spring/config/PersistenceConfig.java new file mode 100644 index 0000000000..6a057fc0c7 --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/spring/config/PersistenceConfig.java @@ -0,0 +1,78 @@ +package org.baeldung.spring.config; + +import java.util.Properties; + +import javax.sql.DataSource; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.PropertySource; +import org.springframework.core.env.Environment; +import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; +import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.springframework.orm.hibernate4.HibernateTransactionManager; +import org.springframework.orm.hibernate4.LocalSessionFactoryBean; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import com.google.common.base.Preconditions; + +// @Configuration +@EnableTransactionManagement +@PropertySource({ "classpath:persistence-mysql.properties" }) +@ComponentScan({ "org.baeldung.persistence" }) +public class PersistenceConfig { + + @Autowired + private Environment env; + + public PersistenceConfig() { + super(); + } + + @Bean + public LocalSessionFactoryBean sessionFactory() { + final LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean(); + sessionFactory.setDataSource(restDataSource()); + sessionFactory.setPackagesToScan(new String[] { "org.baeldung.spring.persistence.model" }); + sessionFactory.setHibernateProperties(hibernateProperties()); + + return sessionFactory; + } + + @Bean + public DataSource restDataSource() { + final DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName"))); + dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("jdbc.url"))); + dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("jdbc.user"))); + dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("jdbc.pass"))); + + return dataSource; + } + + @Bean + public HibernateTransactionManager transactionManager() { + final HibernateTransactionManager txManager = new HibernateTransactionManager(); + txManager.setSessionFactory(sessionFactory().getObject()); + + return txManager; + } + + @Bean + public PersistenceExceptionTranslationPostProcessor exceptionTranslation() { + return new PersistenceExceptionTranslationPostProcessor(); + } + + final Properties hibernateProperties() { + return new Properties() { + { + setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); + setProperty("hibernate.dialect", env.getProperty("hibernate.dialect")); + + // setProperty("hibernate.globally_quoted_identifiers", "true"); + // note: necessary in launchpad-storage, but causing problems here + } + }; + } +} \ No newline at end of file diff --git a/spring-all/src/main/resources/bar.properties b/spring-all/src/main/resources/bar.properties new file mode 100644 index 0000000000..1a41a49c4c --- /dev/null +++ b/spring-all/src/main/resources/bar.properties @@ -0,0 +1 @@ +key.something2=val2 \ No newline at end of file diff --git a/spring-all/src/main/resources/configForProperties.xml b/spring-all/src/main/resources/configForProperties.xml new file mode 100644 index 0000000000..20a40a3195 --- /dev/null +++ b/spring-all/src/main/resources/configForProperties.xml @@ -0,0 +1,15 @@ + + + + + + + + + + \ No newline at end of file diff --git a/spring-all/src/main/resources/configForPropertiesOne.xml b/spring-all/src/main/resources/configForPropertiesOne.xml new file mode 100644 index 0000000000..ad9716fada --- /dev/null +++ b/spring-all/src/main/resources/configForPropertiesOne.xml @@ -0,0 +1,15 @@ + + + + + + + + + + \ No newline at end of file diff --git a/spring-all/src/main/resources/configForPropertiesTwo.xml b/spring-all/src/main/resources/configForPropertiesTwo.xml new file mode 100644 index 0000000000..b9d5e86c95 --- /dev/null +++ b/spring-all/src/main/resources/configForPropertiesTwo.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/spring-all/src/main/resources/foo.properties b/spring-all/src/main/resources/foo.properties new file mode 100644 index 0000000000..7c47cd7880 --- /dev/null +++ b/spring-all/src/main/resources/foo.properties @@ -0,0 +1 @@ +key.something=val \ No newline at end of file diff --git a/spring-all/src/main/resources/logback.xml b/spring-all/src/main/resources/logback.xml new file mode 100644 index 0000000000..45c9697f77 --- /dev/null +++ b/spring-all/src/main/resources/logback.xml @@ -0,0 +1,22 @@ + + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-all/src/main/webapp/WEB-INF/mvc-servlet.xml b/spring-all/src/main/webapp/WEB-INF/mvc-servlet.xml new file mode 100644 index 0000000000..5463820874 --- /dev/null +++ b/spring-all/src/main/webapp/WEB-INF/mvc-servlet.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/spring-all/src/main/webapp/WEB-INF/view/sample.jsp b/spring-all/src/main/webapp/WEB-INF/view/sample.jsp new file mode 100644 index 0000000000..7cc14b5dcd --- /dev/null +++ b/spring-all/src/main/webapp/WEB-INF/view/sample.jsp @@ -0,0 +1,7 @@ + + + + +

This is the body of the sample view

+ + \ No newline at end of file diff --git a/spring-all/src/main/webapp/WEB-INF/web_old.xml b/spring-all/src/main/webapp/WEB-INF/web_old.xml new file mode 100644 index 0000000000..ba2bb591ed --- /dev/null +++ b/spring-all/src/main/webapp/WEB-INF/web_old.xml @@ -0,0 +1,42 @@ + + + + Spring MVC Application + + + + contextClass + + org.springframework.web.context.support.AnnotationConfigWebApplicationContext + + + + contextConfigLocation + org.baeldung.spring.web.config + + + + org.springframework.web.context.ContextLoaderListener + + + + + mvc + org.springframework.web.servlet.DispatcherServlet + 1 + + + mvc + / + + + + index.html + + + \ No newline at end of file diff --git a/spring-all/src/test/java/org/baeldung/ex/nosuchbeandefinitionexception/Cause1NoSuchBeanDefinitionExceptionIntegrationTest.java b/spring-all/src/test/java/org/baeldung/ex/nosuchbeandefinitionexception/Cause1NoSuchBeanDefinitionExceptionIntegrationTest.java new file mode 100644 index 0000000000..aed37a125a --- /dev/null +++ b/spring-all/src/test/java/org/baeldung/ex/nosuchbeandefinitionexception/Cause1NoSuchBeanDefinitionExceptionIntegrationTest.java @@ -0,0 +1,19 @@ +package org.baeldung.ex.nosuchbeandefinitionexception; + +import org.baeldung.ex.nosuchbeandefinitionexception.spring.Cause1ContextWithJavaConfig; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { Cause1ContextWithJavaConfig.class }, loader = AnnotationConfigContextLoader.class) +public class Cause1NoSuchBeanDefinitionExceptionIntegrationTest { + + @Test + public final void givenContextIsInitialized_thenNoException() { + // + } + +} diff --git a/spring-all/src/test/java/org/baeldung/ex/nosuchbeandefinitionexception/Cause2NoSuchBeanDefinitionExceptionIntegrationTest.java b/spring-all/src/test/java/org/baeldung/ex/nosuchbeandefinitionexception/Cause2NoSuchBeanDefinitionExceptionIntegrationTest.java new file mode 100644 index 0000000000..90d7317f44 --- /dev/null +++ b/spring-all/src/test/java/org/baeldung/ex/nosuchbeandefinitionexception/Cause2NoSuchBeanDefinitionExceptionIntegrationTest.java @@ -0,0 +1,19 @@ +package org.baeldung.ex.nosuchbeandefinitionexception; + +import org.baeldung.ex.nosuchbeandefinitionexception.spring.Cause2ContextWithJavaConfig; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { Cause2ContextWithJavaConfig.class }, loader = AnnotationConfigContextLoader.class) +public class Cause2NoSuchBeanDefinitionExceptionIntegrationTest { + + @Test + public final void givenContextIsInitialized_thenNoException() { + // + } + +} diff --git a/spring-all/src/test/java/org/baeldung/ex/nosuchbeandefinitionexception/Cause3NoSuchBeanDefinitionExceptionIntegrationTest.java b/spring-all/src/test/java/org/baeldung/ex/nosuchbeandefinitionexception/Cause3NoSuchBeanDefinitionExceptionIntegrationTest.java new file mode 100644 index 0000000000..0e2123b7ff --- /dev/null +++ b/spring-all/src/test/java/org/baeldung/ex/nosuchbeandefinitionexception/Cause3NoSuchBeanDefinitionExceptionIntegrationTest.java @@ -0,0 +1,19 @@ +package org.baeldung.ex.nosuchbeandefinitionexception; + +import org.baeldung.ex.nosuchbeandefinitionexception.spring.Cause3ContextWithJavaConfig; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { Cause3ContextWithJavaConfig.class }, loader = AnnotationConfigContextLoader.class) +public class Cause3NoSuchBeanDefinitionExceptionIntegrationTest { + + @Test + public final void givenContextIsInitialized_thenNoException() { + // + } + +} diff --git a/spring-all/src/test/java/org/baeldung/properties/core/PropertiesWithJavaIntegrationTest.java b/spring-all/src/test/java/org/baeldung/properties/core/PropertiesWithJavaIntegrationTest.java new file mode 100644 index 0000000000..d6c99502d7 --- /dev/null +++ b/spring-all/src/test/java/org/baeldung/properties/core/PropertiesWithJavaIntegrationTest.java @@ -0,0 +1,30 @@ +package org.baeldung.properties.core; + +import org.baeldung.properties.spring.PropertiesWithJavaConfig; +import org.baeldung.properties.spring.PropertiesWithJavaConfigOther; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.env.Environment; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { PropertiesWithJavaConfig.class, PropertiesWithJavaConfigOther.class }, loader = AnnotationConfigContextLoader.class) +public class PropertiesWithJavaIntegrationTest { + + @Autowired + private Environment env; + + @Value("${key.something}") + private String injectedProperty; + + @Test + public final void givenContextIsInitialized_thenNoException() { + System.out.println("in test via @Value: " + injectedProperty); + System.out.println("in test Environment: " + env.getProperty("key.something")); + } + +} diff --git a/spring-all/src/test/java/org/baeldung/properties/core/PropertiesWithMultipleXmlsIntegrationTest.java b/spring-all/src/test/java/org/baeldung/properties/core/PropertiesWithMultipleXmlsIntegrationTest.java new file mode 100644 index 0000000000..9fc793fc1b --- /dev/null +++ b/spring-all/src/test/java/org/baeldung/properties/core/PropertiesWithMultipleXmlsIntegrationTest.java @@ -0,0 +1,30 @@ +package org.baeldung.properties.core; + +import org.baeldung.properties.spring.PropertiesWithXmlConfigOne; +import org.baeldung.properties.spring.PropertiesWithXmlConfigTwo; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.env.Environment; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { PropertiesWithXmlConfigOne.class, PropertiesWithXmlConfigTwo.class }, loader = AnnotationConfigContextLoader.class) +public class PropertiesWithMultipleXmlsIntegrationTest { + + @Autowired + private Environment env; + + @Value("${key.something}") + private String injectedProperty; + + @Test + public final void givenContextIsInitialized_thenNoException() { + System.out.println("in test via @Value: " + injectedProperty); + System.out.println("in test Environment: " + env.getProperty("key.something")); + } + +} diff --git a/spring-all/src/test/java/org/baeldung/properties/core/PropertiesWithXmlIntegrationTest.java b/spring-all/src/test/java/org/baeldung/properties/core/PropertiesWithXmlIntegrationTest.java new file mode 100644 index 0000000000..ff5eaab910 --- /dev/null +++ b/spring-all/src/test/java/org/baeldung/properties/core/PropertiesWithXmlIntegrationTest.java @@ -0,0 +1,29 @@ +package org.baeldung.properties.core; + +import org.baeldung.properties.spring.PropertiesWithXmlConfig; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.env.Environment; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { PropertiesWithXmlConfig.class }, loader = AnnotationConfigContextLoader.class) +public class PropertiesWithXmlIntegrationTest { + + @Autowired + private Environment env; + + @Value("${key.something}") + private String injectedProperty; + + @Test + public final void givenContextIsInitialized_thenNoException() { + System.out.println("in test via @Value: " + injectedProperty); + System.out.println("in test Environment: " + env.getProperty("key.something")); + } + +} diff --git a/spring-all/src/test/resources/.gitignore b/spring-all/src/test/resources/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/spring-all/src/test/resources/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file