last day (93 days later) » 

4:08 PM
Hi
 
hi
to your question ...
 
I wanted to know if it possible to make @Bean declared in configuration file transactional
 
Yes you can.
If you call a method of the class, the call creates a new sql-transactional-block if there is not a transational-block from another bean.
But you need a bean of type TransactionManager
 
And also how to manage the component scanning hierarchy in a reasonable way. Let's say I have AOP configuration, which needs to access all components in root context, so I import root context to that configuration. but to use that context, I have to import it back to root configuration and this creates circular dependency. Is my only choice to have multiple context, and how to achieve it in MVC as initializer only asks for root context and servlet context
 
What context do you mean? The spring-context?
 
4:17 PM
I have root context, security context (WebSecurityConfigurerAdapter), persistence context and method-level security context (GlobalMethodSecurityConfiguration)
basically i want to do all the scanning in root context and autowire to other context
but importing root context isn't possible as those context are imported to root (would case cirucular dependency) due the design of MVC bootstrap
 
Do you use the @EnableWebSecurity-Annotation?
 
Oh! You did missunderstanding something.
You have exactly one Context, therefore you @Import different Configurations for security, persistence .... Look into the source of @EnableWebSecurity, can you? ...
The @EnableWebSecurity-Annotation has the @Configuration-Annotation and its used for your unique global context. Also it has the @Import-Annotation that imports other @Configurations to your unique global context.
 
but still, i get circular dependency issues if scanning for same packages in different configurations. Does it try to create same bean in each configuration, even if it's just one context? Then what is the best way to glue those configurations together, as many are dependand of other
 
Can you tell me the Exception-Classes that are thrown? I am confused about the "circular dependency".
 
4:31 PM
Severe: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userManager' defined in file [C:\Users\Tuoppi\Desktop\springloginsystem\target\SpringSecureSession-1.0-SNAPSH‌​OT\WEB-INF\classes\com\tuoppi\springsecuresession\service\UserManager.class]: Initialization of bean failed; nested exception is
org.springframework.aop.framework.AopConfigException: Unexpected AOP exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodSecurityInterceptor' defined in class com.tuoppi.springsecuresession.config.MethodSecurityConfig: Bean instantiation via factory method failed;
...
nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'methodSecurityInterceptor': Requested bean is currently in creation: Is there an unresolvable circular reference?
there's much more but chat restricts the message length
 
Ah ok
 
If I only scan for exact classes that configuration uses it works
but it's like many configurations tries to make the same bean, and one that isn't the method interceptor configuration throws that exception I guess
 
See, spring setups the CDI in this order:
1. Call Constructors and store the Instances.
2. Autowire all @Autowire,@Resource,@PersistenceUnit....
3. Call all SmartInitializingSingleton-Bean methods.
Step 1 is done, Step 2 is recursievly and fails

Let me think a second...
 
and it feels stupid to scan for domain objects in security config just to fulfill cross cutting concern. After all, those objects are part of the domain logic and scanning should be done in root configuration and those beans delegated to different configurations
 
Well, drop the idea that there are different configurations. Its one configurations that imports (via @Import) other configurations.
 
4:41 PM
I can send the github repository if you want / have time
 
Sure
 
what branch? circulardep?
 
yes
and in wip it's working, but as you can see I only scan for very specific classes. It feels luck i got it working that why. I want to understand the concept and why it isn't working the other way
 
The rootconfig import PersistenceContext 3 times
Can i start it?
 
4:56 PM
sure
it should work straight away with in memory database
 
tomcat or jetty?
 
I'm deploying on glassfish
 
i use jetty, i see your stacktrace
a big exception with many caused-by
 
5:49 PM
Hard to tell, there is no circular referernce but a recursion. The methodSecurityInterceptor asks the UserService for the right to ask the UserService.
Sorry, anyway if you are using glassfish i can shorten your development-cyclis
Add:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.3.7.v20160115</version>
</plugin>

To the pom in the build/plugins and start `mvn clean compile jetty:run`
 
okay thanks for your effort, I will try the jetty. Enough coding for today thoug. have a nice day sir
 
6:07 PM
You too sir
 

  last day (93 days later) »